react-router4.x和react-router-dom Link組件只有路由變化頁面不能跳轉

關於react-router和 react-router-dom的Link標籤使用時只有路由跳轉,沒有頁面跳轉的問題:

是因爲在配置路由的時候,所有從首頁跳轉到其他頁路由配置,需要在首頁路由之前:

不跳轉
const Routes = ()=>(
        <div className='App'>
            <Router>
                <Switch>
                    <Route path={'/404'} component={NotFound} />
                    <Route path={'/search'} component={Search} />
                    <Route path={'/result'} component={Result} />
                    <Route path={'/'} component={Home} />
                    <Route path={'/albumlist'} component={AlbumList} />
                    <Redirect from={"*"} to={'/'} />
                </Switch>
            </Router>
        </div>
)
export default Routes;

修改之後跳轉:
const Routes = ()=>(
        <div className='App'>
            <Router>
                <Switch>
                    <Route path={'/404'} component={NotFound} />
                    <Route path={'/search'} component={Search} />
                    <Route path={'/result'} component={Result} />
                    <Route path={'/albumlist'} component={AlbumList} />
                    <Route path={'/'} component={Home} />
                    <Redirect from={"*"} to={'/'} />
                </Switch>
            </Router>
        </div>
)
export default Routes;

比如說我這裏遇到的不跳轉,就是因爲我把跳到"/albumlist"這個頁面的路由放到了首頁路由之後,隨便我按照網上其他人說的加什麼withRouter都沒用,後來我突然靈光一閃,把"/albumlist"的路由放到首頁路由之前,就跳轉了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章