码迷,mamicode.com
首页 > 其他好文 > 详细

React dva/dynamic 参数

时间:2019-01-07 20:58:44      阅读:328      评论:0      收藏:0      [点我收藏+]

标签:参数   dynamic   outer   rop   pre   style   win   map   const   

 
 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

React dva/dynamic 参数

标签:参数   dynamic   outer   rop   pre   style   win   map   const   

原文地址:https://www.cnblogs.com/liujiaxun/p/10234888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!