React dva/dynamic 参数


 
 1 import dynamic from 'dva/dynamic';
 2 import { Route, Switch, Redirect } from 'dva/router';
 3 export const newDynamic = (app,model,component) => {
 4     // console.log(app,model,component);
 5     return dynamic({
 6         app,
 7         models:() => model,
 8         component
 9     })
10 }
11 /**
12  * @param {app} app
13  * @param {func} routerConfig 
14  */
15 export const createRouters = (app,routerConfig) => {
16     return (
17         <Switch>
18             {
19                 routerConfig(app).map( config => createRouter( app,() => config ))
20             }
21         </Switch>
22     )
23 
24 }
25 
26 export const createRouter = (app,routerConfig) => {
27     const { 
28         title,
29         path,
30         indexRouter,
31         component:Comp,
32         ...otherProps
33     } = routerConfig(app);
34     if (path && path !== '/') {
35         window.dva_router_pathMap[path] = { path, title, ...otherProps };
36     }
37     if(path === '/login'){
38         console.log(routerConfig(app).component,'routerConfig');
39     }
40     const routePorps = Object.assign({
41         key:path || '/404',
42         render:props => <Comp routerData={otherProps} {...props} />
43     },
44     path && {
45       path: path
46     });
47     if(path === '/login'){
48         console.log(routePorps,'/sign/login')
49       }
50     if(indexRouter){
51         return [
52             <Redirect key={path + '_redirect'} exact from={path} to={indexRouter} />,
53             <Route {...routePorps} />
54           ];
55     }
56     return <Route {...routePorps} />;
57 }

生成动态dva路由,其中 dynamic  需要注意 里面json参数顺序,app , models , component


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM