在 Meteor 中使用 react-router 3 到 4 重构身份验证
Refactor authentication using react-router 3 to 4 in Meteor
我想使用 react-router v4 而不是 v3 更新 meteor 应用程序中的授权。
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) 看到了示例。但是还是不知道怎么做。
这是 Meteor Chef 的一篇很棒的文章,解释了如何使用 React Router V4。他还向您展示了如何处理身份验证!
我想使用 react-router v4 而不是 v3 更新 meteor 应用程序中的授权。
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) 看到了示例。但是还是不知道怎么做。
这是 Meteor Chef 的一篇很棒的文章,解释了如何使用 React Router V4。他还向您展示了如何处理身份验证!