我需要用相同的js/bundle.js文件响应每个react-app请求,但不做实际的重定向-让url保持不变。因为在bundle.js返回- react-router之后,路由器将从该bundle.js文件中获得所需的任何页面。
当在url中时,有一个"/“-重新加载页面/welcome或任何其他方式都可以正常工作。
但是当我尝试重新加载/auth/login (两个斜杠)时,它试图从auth/js/bundle.js中查找bundle.js,并给出了一个错误。
我正在使用
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ /index.html [L]但这并不管用。
这是我的react-router
function requireAuth(nextState, replace) {
if (!localStorage.mazoomToken) {
replace({
pathname: '/auth/login',
state: { nextPathname: nextState.location.pathname }
})
}
}
function hasAuth(nextState, replace) {
if (localStorage.mazoomToken) {
replace({
pathname: '/',
state: { nextPathname: nextState.location.pathname }
})
}
}
const router = (
<Provider store={store}>
<Router history={history}>
<Route path="/" onEnter={requireAuth} component={App}>
<IndexRoute component={Events}/>
<Route path="welcome" component={WelcomePage} onEnter={requireAuth}/>
<Route path="contacts" component={Contacts} onEnter={requireAuth}/>
<Route path="profile" component={Account} onEnter={requireAuth}/>
</Route>
<Route path="/auth/" component={Auth} onEnter={hasAuth}>
<Route path="sign_up" component={SignUp} onEnter={hasAuth}/>
<Route path="login" component={Login} onEnter={hasAuth}/>
<Route path="forgot_pass" component={ForgotPassword} onEnter={hasAuth}/>
<Route path="password/:token" component={NewPassword} onEnter={hasAuth}/>
</Route>
</Router>
</Provider>
);提前感谢您的帮助!
发布于 2016-10-12 23:54:37
问题出在index.html -当链接脚本js/bundle.js时,我没有把斜杠放在js - /js/index.js之前。
https://stackoverflow.com/questions/40000840
复制相似问题