鍍金池/ 問答/HTML5  HTML/ react-router 4中,路由無法直接訪問,或者跳轉(zhuǎn)

react-router 4中,路由無法直接訪問,或者跳轉(zhuǎn)

頁面結(jié)構(gòu):
RootMap:

            <BrowserRouter history={this.props.history}>
              <Switch>
                    <Route exact path='/' component={Login}/>
                    <Route path='/login' component={Login}/>
                    <Route path='/home' component={Home}/>
                    <Route component={NotFound}/>
              </Switch>
            </BrowserRouter>

Home內(nèi)結(jié)構(gòu):

      <BrowserRouter>
        <div>
          <Head/>
          <Aside/>
          <switch>
            <Route exact path='/home' component={Container}/>
            <Route path='/home/dashboards' component={Container}/>
            <Route path='/home/setedge' component={SetEdge}/>
            <Route path='/home/controls' component={Controls}/>
          </switch>
        </div>
      </BrowserRouter>
      

SetEdge內(nèi)結(jié)構(gòu):

      <BrowserRouter>
        <Switch>
            <Route exact path='/home/setedge' component={SetIot}/>
            <Route path='/home/setedge/setiot' component={SetIot}/>
            <Route path='/home/setedge/setdevice' component={SetDevice}/>
          </Switch>
      </BrowserRouter>
      
      

頁面結(jié)構(gòu)如上,現(xiàn)在我能進入/home和/login,但是就是不能直接進入/home/setedge,子路由的所有路由全都不能進去,但是如果先進/home,再點擊菜單中的跳轉(zhuǎn),就能進入/home/setedge

而且我現(xiàn)在如果在/home/setedge/setiot下,點擊返回按鈕,觸發(fā),this.props.history.push('/home/setedge');瀏覽器中路由變化了,但是頁面回不去。沒效果

問題一,我改怎么寫路由,才能我隨意輸入一個路由就能進去,不用一層一層的進去,先進/home,再點擊菜單中的跳轉(zhuǎn),進入/home/setedge,而是直接瀏覽器路由填寫/home/setedge進入。

問題二,我該怎么設(shè)置頁面跳轉(zhuǎn),才能讓路由生效

回答
編輯回答
陌南塵

只保留最外層的一個 BrowserRouter ,你再試試

2018年8月31日 06:04
編輯回答
詆毀你

我也遇到了 樓主解決了嗎 直接訪問不行 只能通過連接點擊,而且點擊時明明url已經(jīng)改變了

2017年11月9日 17:23
編輯回答
薄荷糖

我也遇到了同樣的問題,請問解決方案是什么?

2018年5月3日 03:52