React router v.4不渲染嵌套的Component

时间:2017-12-13 16:03:30

标签: javascript reactjs router

我的路由器配置:

export default [
  {
    exact:true,
    path: '/',
    component: Dashboard, // Add your route here

  },


  {

    path: '/backupjobs',
    component: Backup, // Add your route here
    routes: [
      { 

        path: '/backupjobs/jobdetail',
        component: Alert
      }
    ]
  },

我尝试渲染组件警告与子路由一样。但它始终显示组件备份

我使用的链接:

<Link className="link-table" to={`${this.props.match.url}/jobdetail`}>Alert</Link>

我的路由器看起来如何:

routeWithSubRoutes(route) {
  return (
    <Route
      key={_.uniqueId()}
      exact={route.exact || false}
      path={route.path}
      render={props => (
        // Pass the sub-routes down to keep nesting
        <route.component {...props} routes={route.routes || null} />
      )}
    />
  );
 } 

<Switch>
      {routes.map(route => this.routeWithSubRoutes(route))}
      </Switch>

在浏览器中更改了URL地址,但始终显示备份组件

0 个答案:

没有答案