I want to extend <Route> component of react-router-dom so it would prepend some value before path property. It would look like this:
export default function MyRoute({path, ...rest}) {
const newpath = '/app' + path;
return <Route path={newpath} {...rest} />
}
I want to use it like:
<MyRoute path="/login" component={Login} />
So behind the scenes it should render:
<Route path="/app/login" component={Login} />
When I go to /app/login url it doesn't load. <Login /> still shows up only on /login.
What am I doing wrong here?
Edit
It doesn't work when used directly inside <Switch>:
<Switch>
<MyRoute path="/login" />
</Switch>
But works when moved to another component:
<Switch>
<Routes />
</Switch>
and Routes beeing:
<>
<MyRoute path="/login" />
</>