-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic route #150
Dynamic route #150
Conversation
Great job!
|
@WhatAKitty Could you help us updating the relevent document meanwhile? https://pro.ant.design/docs/layout-cn |
@afc163 ok, I will. |
I have updated doc just now. |
src/layouts/BasicLayout.js
Outdated
@@ -142,7 +142,7 @@ class BasicLayout extends React.PureComponent { | |||
<Link to={itemPath} target={item.target}> | |||
{icon}<span>{item.name}</span> | |||
</Link> | |||
) | |||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
@afc163 Updated. |
啥时候更新上去呢, 正要启动一个新项目呢 |
}, { | ||
path: 'result', | ||
component: Step3, | ||
component: app => dynamic({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here should return <Component />
rather than a dynamic function ,so this error occurs:
Functions are not valid as a React child. This may happen if you return a Component instead of from render. Or maybe you meant to call this function rather than return it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot reproduce this issue,Could you show your code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是copy你的代码的pull request啊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/WhatAKitty/ant-design-pro please try again. This repo is ok and works good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And please note: If you use webpack instead of dva rodhog, please install [email protected]. the [email protected] version fix import issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
找到原因了,子组件写错了,Form.create()(Login)写成了Form.create(Login),抱歉
I will handle this after dvajs/dva#1332 |
Merged in d93b0bf |
@WhatAKitty 现在有个性能问题,左边菜单展开收起时,右侧内容会整体重新渲染(触发 componentDidMount)。 |
@afc163 这个问题我没察觉到,我看下。不过是否可能因为动态加载未判断不需要刷新页面的情况? |
啥? |
@afc163 就是是否可以通过生命周期的componentWillReceiveProps来判断是否需要刷新页面的情况 |
不应该这么做,页面代码不应该关心这个。 ant-design-pro/src/layouts/BasicLayout.js Line 355 in 5c6de66
可能是这里用了函数调用的缘故。 |
@afc163 想到一个办法,在routeConfig内部事先完成
common.nav.js
测试了一下,不会重复加载了。 |
* Update doc with dynamic router support * Load demand * Change doc for ant-design/ant-design-pro#150 * Documentation with dynamicWrapper
@WhatAKitty 每次点击Link组件发生路由变化都会导致routes中的组件重新挂载,生命周期从didMount重新执行了数据获取等操作,这是react-router4引入的么,怎么避免重新挂载呢,现在需要使用tab进行页面的切换,同时保持各个tab页面中state不变化 |
@afc163 我fetch了master的最新代码在本地调试,在https://preview.pro.ant.design/#/dashboard/analysis 也试了一下,还是会重新fetch数据啊 |
@sbyps 并不会重新加载啊。preview上也没看到有重新fetch数据。组件本身,在动态引入后,不会重新加载第二次,而是会缓存这个组件。 |
@WhatAKitty 现在正在本地调试呢,在左侧菜单切换时,每个页面的componentDidMount又执行了,有其他联系方式么 |
@sbyps 切换菜单的话,componentDidMount的确会执行,不过这个是正常现象吧。 |
@WhatAKitty 按照我理解mount一次就好了啊,那不是从头又执行了一整遍生命周期。这样也多次请求了数据,触发了model的变化 |
@sbyps 这个的确是个问题,性能上考虑,最好第一次加载完毕后,后几次仍旧使用之前的实例。数据的变更通过 |
@afc163 @nikogu 这种加载形式需要涉及dynamic,是否考虑使用https://github.com/faceyspacey/react-universal-component 替换dva的动态加载? |
@sbyps 目前来说,重新渲染一遍花费的代价并不大,
|
@WhatAKitty 代价可能还好说,就是动态加载的组件之前的数据state保存不下来,比如翻页等,这点我觉得是个问题。不过是否需要保存也是可以讨论的 |
@sbyps 数据的话,如果你使用了dva的话,那么按照dva的设计,数据是保存在model里面的,除非你自己将某些数据存储到了component级别。 编辑: |
@WhatAKitty 那也不是所有数据都在model里吧,我还是认为一些通用的数据放到model里好,一些就是组件内部用的还是保存在组件内部好一些,不然就是每个页面都要对应一个model了,这样很庞大也很多余吧 |
@sbyps 担心这个的话,可以看这个dvajs/dva#77 ,这个问题是讨论过的。 |
@WhatAKitty 还是认为再mount一次不是很合适,应该是recieveprops比较好,有什么解决思路吗 |
@WhatAKitty 你这个关于state的思考我也很认同,但好像话题偏了=。= 在这个动态路由的情况下,组件是否还需要重新执行生命周期 |
something maybe helpful remix-run/react-router#4578 |
不小心发散开来了 |
@afc163 在react-router的issue里面看了一圈,去除HOC并为routes设置相同的key能解决?我在本地试了一下好像还不行额。这个issue说的是path不同,同一个component不会被remount,但现在是不同的component,所以还是会被remount吧 |
No description provided.