我正在使用redux处理react js应用程序。路由器使用注入器实现。如何确保身份验证。如果用户使用url直接导航到某个页面,则必须执行检查以查看他是否已登录。下面是代码
export default function createRoutes(store) {
// Create reusable async injectors using getAsyncInjectors factory
const { injectReducer, injectSagas } = getAsyncInjectors(store);
return [
{
path: '/',
name: 'login',
getComponent(nextState, cb) {
const importModules = Promise.all([
System.import('Controller/LoginViewController'),
System.import('Controller/LoginViewController/reducer'),
System.import('Controller/LoginViewController/sagas'),
]);
const renderRoute = loadModule(cb);
importModules.then(([component,loginReducer,loginSagas]) => {
injectReducer('loginViewController',loginReducer.default);
injectSagas('loginViewController',loginSagas.default);
renderRoute(component);
});
importModules.catch(errorLoading);
}
}