Reactjs 使用代码拆分对路由器作出反应,替换()不工作
我正在使用代码拆分的react router v3.0.2。我提出了以下问题: 如果未传递Reactjs 使用代码拆分对路由器作出反应,替换()不工作,reactjs,webpack,redux,react-router,react-router-redux,Reactjs,Webpack,Redux,React Router,React Router Redux,我正在使用代码拆分的react router v3.0.2。我提出了以下问题: 如果未传递userRoleurl参数,但replace()函数未启动,且控制台中没有错误,则需要重定向 export default (store) => { return <Route path="project(/:userRole)" onEnter={(nextState, replace, cb) => { if (__CLIENT__) {
userRole
url参数,但replace()
函数未启动,且控制台中没有错误,则需要重定向
export default (store) => {
return <Route
path="project(/:userRole)"
onEnter={(nextState, replace, cb) => {
if (__CLIENT__) {
const res = validateUserRole(nextState, replace);
if(res === true){
dispatchProjectList(store, nextState, replace, cb).then(() => {
cb();
}).catch((e) => {
console.error(e.stack);
cb();
});
}
else {
replace(`/project/${res}`);
}
}
cb();
}}
getComponent={(location, cb) => {
System.import('../../views/project/components/Project')
.then((module) => {
cb(null, module.default);
})
.catch(errorLoading);
}}
/>
导出默认值(存储)=>{
返回{
如果(客户机){
const res=validateUserRole(下一状态,替换);
如果(res==true){
dispatchProjectList(存储、下一状态、替换、cb)。然后(()=>{
cb();
}).catch((e)=>{
控制台错误(如堆栈);
cb();
});
}
否则{
替换(`/project/${res}`);
}
}
cb();
}}
getComponent={(位置,cb)=>{
System.import(“../../views/project/components/project”)
。然后((模块)=>{
cb(null,module.default);
})
.捕获(错误加载);
}}
/>
如果执行了else
,则需要检查validateUserRole
并记录。没有理由replace
不起作用。@DeividasKaržinauskas谢谢你的回复,我已经这么做了。它只是忽略了replace()
函数。因此,如果在之前运行replace
,如果({code>CLIENT}{…}
,它也不工作?是validateUserRole
同步吗?@devidaskaržinuskasvalidateUserRole
是同步的。如果我注释掉所有onEnter
hook,则得到的警告:[react router]Location”/project“与任何路由都不匹配