0

我想使用 react-router v4 而不是 v3 更新流星应用程序中的授权。

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('/');
  }
});  

我从官方 react-router 文档页面(https://reacttraining.com/react-router/web/example/auth-workflow)中看到了示例。但是还是不知道怎么做。

4

1 回答 1

1

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

教程

于 2017-04-13T12:05:40.493 回答