2017-09-21 20 views
3

我使用React Router v4創建了React/Redux應用程序。它具有結構簡單React App刷新後返回錯誤

--RootPage path/
--HomePage path /h 
    -Gallery path /h/portfolio 
    -Links  path /h/links 
    -About  path /h/about 

現在,我每次刷新的時間,如果我在第二級/ H /組合,或/ H /鏈接,或/ H /一下,這個錯誤淨:: ERR_ABORTED。如果我的根目錄下或/ H /水平

enter image description here

刷新工作正常。我已經將historyApiFallback: true添加到devServer,所以不是這個問題。每次刷新時都必須始終轉到/ root,這沒有任何意義。這裏有什麼可能是錯的?

這裏是我的路線

const mainRouter=(
    <Wrapper> 
<Provider store={store} history={history}> 
    <BrowserRouter> 
     <div> 
     <Route exact path="/" component={Home}/> 
     <Route path="/h" component={HomePage}/> 
     </div> 
    </BrowserRouter> 
    </Provider> 
    </Wrapper> 
) 

而且在首頁

 <main> 
      <Route path={`${this.props.match.path}/portfolio`} 
      render={()=><Gallery {...this.props}/> } /> 
      <Route path={`${this.props.match.path}/about`} render={()=><About 
      {...this.props}/> }/> 
      <Route path={`${this.props.match.path}/links`} render={()=><Links 
      {...this.props}/> }/> 

     </main> 
+0

加入output.path.publicPath:"/"在您的主頁路線的'render'道具來解決它,嘗試這個回調:'(props)=><關於{... this.props} {... props} />' – SrThompson

+0

在改變它之前,它與'render'沒有任何關係,導致問題)。當我添加二級路徑時,這個問題就開始了。 – Ndx

+0

爲什麼你將'history'傳遞給'Provider'而不是讓'react-router'處理呢? – SrThompson

回答

5

再生Express服務器,而不是devserver同樣的問題後,我得到了同樣的錯誤,並做一些研究,我發現這simple fix對此問題

我只需要將<script src="js/app.bundle.js"></script>更改爲<script src="/js/app.bundle.js"></script>

編輯:如果您使用的WebPack-HTML的插件,我這樣做,它仍然給同樣的錯誤,我不得不通過的WebPack配置文件