首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache不会正确地重定向url中包含2个以上斜杠的react请求

Apache不会正确地重定向url中包含2个以上斜杠的react请求
EN

Stack Overflow用户
提问于 2016-10-12 22:10:24
回答 1查看 362关注 0票数 0

我需要用相同的js/bundle.js文件响应每个react-app请求,但不做实际的重定向-让url保持不变。因为在bundle.js返回- react-router之后,路由器将从该bundle.js文件中获得所需的任何页面。

当在url中时,有一个"/“-重新加载页面/welcome或任何其他方式都可以正常工作。

但是当我尝试重新加载/auth/login (两个斜杠)时,它试图从auth/js/bundle.js中查找bundle.js,并给出了一个错误。

我正在使用

代码语言:javascript
复制
    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

代码语言:javascript
复制
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>
);

提前感谢您的帮助!

EN

回答 1

Stack Overflow用户

发布于 2016-10-12 23:54:37

问题出在index.html -当链接脚本js/bundle.js时,我没有把斜杠放在js - /js/index.js之前。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40000840

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档