我這里有一個路線列表,這是一個頂部導航。當我單擊每個項目時,它會轉到該路線。一旦我進入子路線并單擊頂部導航之一,它就會從我的路線中添加路徑,而無需清除路線。例子/api > 從這條路線我可以去任何地方/api/id > 但是從這里如果我單擊/api鏈接到頂部導航它會更改為/api/id/api應用程序.jsx <BrowserRouter> <div className="App"> <Navigation /> <Switch> <Route path="/apis" exact component={SwagUI}/> <Route path="/myaccount" exact component={MyAccount}/> <Route path="/myapps" exact component={MyApps}/> <Route path="/apis/:id" component={SwaggerAPI} /> </Switch></div> </BrowserRouter>導航.jsx <ul class="navbar pull-right"> <NavLink exact to="admindashboard"><li>Admin Dashboard</li></NavLink> <NavLink exact to="apis"><li>APIs</li></NavLink> <NavLink exact to="general"><li>General info</li></NavLink> <NavLink exact to="contactus"><li>Contact</li></NavLink> <NavLink exact to="myapps"><li>My Apps</li></NavLink> <NavLink exact to="faqs"><li>FAQs</li></NavLink> <NavLink exact to="notification"><li>Notifications</li></NavLink> </ul>
無法從子路由到父路由 - ReactJS
收到一只叮咚
2021-10-21 15:08:07