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 /水平
刷新工作正常。我已經將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>
加入
output.path.publicPath:"/"
在您的主頁路線的'render'道具來解決它,嘗試這個回調:'(props)=><關於{... this.props} {... props} />' – SrThompson在改變它之前,它與'render'沒有任何關係,導致問題)。當我添加二級路徑時,這個問題就開始了。 – Ndx
爲什麼你將'history'傳遞給'Provider'而不是讓'react-router'處理呢? – SrThompson