好吧,我厌倦了尝试.
该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")
Run Code Online (Sandbox Code Playgroud)
编辑:
我打电话时执行该方法onEnter={requireAuth()},但显然这不是目的,我也不会得到所需的参数.