1

This is how I use it, and I don't think there should be much of a problem:

export const ListScreen = ()=>{
    return (
        <>
            <h1>ListScreen</h1>
            <Link to={"/kanban"}>kanban</Link>
            <Link to={"/epic"} >epic</Link>
            <Routes>
                <Route path={"kanban"} element={<KanbanScreen/>}/>
                <Route path={"epic"} element={<EpicScreen/>}/>
                <Navigate to={window.location.pathname + "/kanban"}/>
            </Routes>
        </>
    )
}

enter image description here

I am using react-router version 6.2.1

keikai
  • 14,085
  • 9
  • 49
  • 68
bearbaba
  • 23
  • 3
  • Does this answer your question? [Navigate is not a component. All component children of must be a or ](https://stackoverflow.com/questions/70171991/navigate-is-not-a-route-component-all-component-children-of-routes-must-be) – TheTisiboth Dec 21 '21 at 14:19

1 Answers1

3

You can find the anwser here: Routes component only accept Route component as child

So in your case, instead of using directly <Navigate /> in the Routes component, I'd rather do like this:

<Route path="*" element={<Navigate to={window.location.pathname + "/kanban"}/>}

But instead of redirecting, it would make more sense (to me) to have a default Route instead, that points directly to the default component to display, like this:

<Route path="*" element={<KanbanScreen/>}
TheTisiboth
  • 1,431
  • 1
  • 6
  • 13