dva路由跳转

clipboard.png
这是页面

clipboard.png
这是路由

这样跳转的话 是无效的,页面直接跳转到404了。
请问dva的路由要怎么跳转 ?

阅读 12.2k
1 个回答

你这个写的是低版本的异步路由,getComponent不起作用
下面这个是2.0的写法,你可以参考下

import dynamic from 'dva/dynamic';

const RouterConfig = ({ history, app}) => {
  const notFound = dynamic({
    app,
    component: () => import('./routes/404')
  });
  const home = dynamic({
    app,
    component: () => import('./routes/home')
  });
  const homeChild = dynamic({
    app,
    component: () => import('./routes/child')
  });
return(
    <Router history={history}>
      <Switch>
        <Route path='/home' exact component={home} />
        <Route path='/home/child' exact component={homeChild} />
        <Route path='*' exact component={notFound} />
      </Switch>
    </Router>
  )