Я использую реагирующий маршрутизатор и хочу знать, как можно использовать оба маршрута, например: x.com/posts и x.com/posts/3
в маршруте / postsЯ хочу показать весь список сообщений, а в / posts / 3 я хочу показать подробности сообщения
Да!это возможно.проверить это объяснение от реагировать на документы маршрутизатора :
function App() { return ( <div> <Switch> {/* If the current URL is /about, this route is rendered while the rest are ignored */} <Route path="/about"> <About /> </Route> {/* Note how these two routes are ordered. The more specific path="/contact/:id" comes before path="/contact" so that route will render when viewing an individual contact */} <Route path="/contact/:id"> <Contact /> </Route> <Route path="/contact"> <AllContacts /> </Route> {/* If none of the previous routes render anything, this route acts as a fallback. Important: A route with path="/" will *always* match the URL because all URLs begin with a /. So that's why we put this one last of all */} <Route path="/"> <Home /> </Route> </Switch> </div> ); }