【发布时间】:2017-08-03 18:19:30
【问题描述】:
好吧,我受够了尝试。onEnter 方法不起作用。知道为什么吗?
// Authentication "before" filter
function requireAuth(nextState, replace){
console.log("called"); // => Is not triggered at all
if (!isLoggedIn()) {
replace({
pathname: '/front'
})
}
}
// Render the app
render(
<Provider store={store}>
<Router history={history}>
<App>
<Switch>
<Route path="/front" component={Front} />
<Route path="/home" component={Home} onEnter={requireAuth} />
<Route exact path="/" component={Home} onEnter={requireAuth} />
<Route path="*" component={NoMatch} />
</Switch>
</App>
</Router>
</Provider>,
document.getElementById("lf-app")
编辑:
当我调用onEnter={requireAuth()}时该方法被执行,但显然这不是目的,我也不会得到想要的参数。
【问题讨论】:
-
你使用的是哪个 react-router 版本?
标签: javascript reactjs react-router react-router-v4