I have a React app, and I do not want to replicate the functionality in all my components to redirect the user to /<component>/list if they go to /<component> - how would I do this at a higher level?
I have a layout component that would be the place to do it if I were to guess. I have a getRoutes method in there that processes a routes definitions file. However, what I would like to do, is provide a list of components that must redirect to that /<component>/list path if they go to one of the components in that list:
List: ['/templates', '/activities', '/trials']
Visiting:
/templates: redirects to `/templates/list`
/activities: redirects to `/activities/list`
/custom: does nothing, renders CustomComponent
/trials: redirects to `/trials/list`
/trials/new: does nothing, renders new method
Is this possible? I tried using , but was unsuccessful at capturing items without the path being explicitly defined:
<Switch>
<Route path="/templates">
{<Redirect to="/templates/list"/>}
</Route>
...
</Switch>
Is there a way to do it something like this? :
var paths = ['templates', 'trials'];
getRoutes = routes => {
return (
[if path matches /{paths[0..n]]
<Redirect to={{pathname: /paths[0..n]/list}} />
[/if]
);
}
I don't think I am on the right track here, but is there something similar to what I am trying to accomplish?