点击切换路由时验证登陆

2017-09-08  本文已影响22人  Ysj1111

onEnter钩子还可以用来做认证。

const requireAuth = (nextState, replace) => {
if (!auth.isAdmin()) {
// Redirect to Home page if not an Admin
replace({ pathname: '/' })
}
}
export const AdminRoutes = () => {
return (
<Route path="/admin" component={Admin} onEnter={requireAuth} />
)
}

上一篇下一篇

猜你喜欢

热点阅读