React Router - 如何使用动态路由重定向IndexRedirect

时间:2017-03-04 14:17:22

标签: reactjs react-router

以前,我将所有路由放在一个文件中,就像这样

const rootRoute = {
    childRoutes: [{
        path: '/',
        component: require('./containers/App'),
        childRoutes: [
            require('./routes/app'),
            require('./routes/404'),
        ]
    }]
}

render(
    <Provider store={store}>
        <Router
            onUpdate={scrollToTop}
            history={history}
            routes={rootRoute}
        />
    </Provider>,
    document.getElementById('app-container')
)

但现在,我使用dynamic routing,并将代码分开

/

我的问题是,我现在怎样才能将/app/dashboard转移到*

此外,像以前一样将所有其他网页/404重定向到html, body, #fullheight { min-height:10%; display: table; } body { background: red; } #fullheight { width: 250px; background: blue; } listen , height:100% is not realy true! you can use height:auto or use px em

非常感谢!

1 个答案:

答案 0 :(得分:2)

您必须使用 onEnter 事件 应该是这样的:

const rootRoute = {
    path: '/',
    component: require('./containers/App'),
    indexRoute: { onEnter: (nextState, replace) => replace('/app/dashboard') },
    childRoutes: [
        require('./routes/app'),
        require('./routes/404'),
    ]
}