【问题标题】:History API fallback fails on refresh历史 API 回退在刷新时失败
【发布时间】:2017-12-05 23:16:35
【问题描述】:

我在我的 webpack 开发服务器上启用了历史 api 回退选项,当我尝试直接访问或刷新我的 /complete/incomplete 路由时,它工作正常。但是 - 在我的 switch 语句中,我试图捕获所有其他可能的 url 并重定向到 404 组件。

<Switch>

    <Route exact path={'/'} render={()=>{
        return <Redirect to='/incomplete'/>
    }}/>

    <Route exact path={'/complete'} render={()=>{
        return ( <TodoComplete/> );
    }}/>

    <Route exact path="/incomplete" render={()=>{
        return ( <TodoIncomplete/> );
    }}/>

    <Route component={NotFound}/>

</Switch>

这似乎工作正常,并且可以正确路由到 NotFound 组件,以获取像 http://localhost.com/undefinedroute 这样的 URL 但似乎没有捕获任何嵌套的内容,例如 http://localhost.com/complete/undefinedroute

我得到一个控制台错误,说我的资源正试图从不正确的路径http://localhost.com/complete/bundle.js加载

这是预期的行为吗?

【问题讨论】:

    标签: reactjs webpack react-router webpack-dev-server


    【解决方案1】:

    在你的 index.html 中放 /bundle.js

    <script src='/bundle.js'></script>
    

    【讨论】:

      【解决方案2】:

      根据文档,这似乎是预期的行为。但是,关于这种行为有一个很大的线程here,他们可能很快就会改变这一点。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-04-18
        • 1970-01-01
        • 1970-01-01
        • 2018-09-10
        • 1970-01-01
        • 1970-01-01
        • 2011-03-26
        • 2010-09-08
        相关资源
        最近更新 更多