2017-04-13 27 views
0

我想使用react-router v4而不是v3来更新meteor应用程序的授权。在流星中使用react-router 3到4的重构认证

Tracker.autorun(() => { 
    const isAuthenticated = !!Meteor.userId(); 
    const pathname = browserHistory.getCurrentLocation().pathname; 
    const isUnauthenticatedPage = unauthenticatedPages.includes(pathname); 
    const isAuthenticatedPage = authenticatedPages.includes(pathname); 

    if (isUnauthenticatedPage && isAuthenticated) { 
    browserHistory.replace('/links'); 
    } else if (isAuthenticatedPage && !isAuthenticated) { 
    browserHistory.replace('/'); 
    } 
}); 

我见过官方反应路由器文档页面(https://reacttraining.com/react-router/web/example/auth-workflow)的例子。但仍然不知道要做到这一点。

回答

1

这是Meteor Chef的一篇很棒的文章,解释了如何使用React Router V4。他向您展示了如何处理身份验证!

Tutorial