slow-yellowS
Refine•4y ago•
1 reply
slow-yellow

Conditional fallback routing logic, is this possible?

Hi all, is it possible to create a conditional routing logic?

e.g. route: /custom/edit/:id

if id is null
- query first user's custom object, then redirect to the custom edit page
- if no custom objects are assigned to the user, then redirect to another page

I've been able doing it adding a custom route like

routes: [ .... { path: 'custom/edit', element: <AutoRedirect />, } ]

and in the AutoRedirect component i've added the logic.

It works BUT I correctly get an error like "Warning: Cannot update a component (BrowserRouter) while rendering a different component (AutoRedirect). To locate the bad setState() call inside AutoRedirect, follow the stack trace as described ..."

so, it works but it's not the correct way to manage it 🙂 how should I manage this situation?
Was this page helpful?