I'm currently working on a forum-type project for fun and experience, using Router to handle loading boards and threads from MongoDB. I've enocuntered a problem- board URLs work, but trying to nest a thread URL within that (i.e. get thread number XX in board YY):
{ path: "/board/:id", element: <BoardPage />, children: [{ path:"/board/:id/:tid", element: <ThreadPage /> }],Just returns the board page. Now the thing is I have actually solved this, but it's somewhat... silly.
{ path: "/board/:id", element: <BoardOrThread />, children: [{ path:"/board/:id/:tid", element: <BoardOrThread /> }],function BoardOrThread(props) {const params = useParams();//if ('tid' in params)if (params.hasOwnProperty('tid')) {return(<ThreadPage params={params} />);}//else...return(<BoardPage params={params} />);}Basically, the BoardOrThread component checks if the tid (thread ID) value exists in params, if it does it returns an instance of the ThreadPage component, else it returns a BoardBage. This works, but almost certainly not how this is supposed to be done. Is what I'm trying to do possible, and if so, how do I do it properly?