简体   繁体   中英

How can React-Router-Dom v6 properly distribute internal routers among components?

There is routing at the top level with internal routing, the question arose to add routing inside components such as ProductsPage, ElementsPage, etc.

                <BrowserRouter>
                    <Routes>
                        <Route path='/' element={<PageLayout />}>
                            <Route path='marketplace'>
                                <Route path='products' element={<ProductsPage />} />
                                <Route path='constituents' element={<ElementsPage />} />
                                <Route path='resources' element={<ResourcesPage />} />
                                <Route path='shopping' element={<ShoppingPage />} />
                            </Route>
                            <Route path='resource-center'>
                                <Route path='planner' element={<>планирование</>} />
                                <Route path='resources' element={<>resources</>} />
                            </Route>
                            <Route path='*' element={<>Страница не найдена 404</>} />
                        </Route>
                    </Routes>
                </BrowserRouter>

The question is how to do this in version 6. Because before version five, you could easily throw a switch into a component a la ProductsPage and specify routes in the switch

You can name all pages explicitly.

 <BrowserRouter> <Routes> <Route path='/' element={<PageLayout />} /> <Route path='/marketplace/products' element={<ProductsPage />} /> <Route path='/marketplace/constituents' element={<ElementsPage />} /> <Route path='/marketplace/resources' element={<ResourcesPage />} /> <Route path='/marketplace/shopping' element={<ShoppingPage />} /> <Route path='/resource-center/planner' element={<планирование />} /> <Route path='resource-centerresources' element={<resources/>} /> <Route path='*' element={<Страница не найдена 404/>} /> </Routes> </BrowserRouter>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM