Detect the current route in a view

I have a header bar. I would like to enable some controls if a user is in a particular route. For example, if a user is viewing a dashboard page, I want to enable a Create button on the header bar. It looks like react-router utilities are not available in redwoodjs. I end up doing some pathname matching. It’s not ideal.

Is there a way to detect the current route in a view? Maybe routes object can return current() with the route’s name and params (e.g. id). So when a user is viewing “/dashboards/1234”, routes.current() will return {name: “viewDashboard”, id: "1234}.

Hi @dnprock! Have you tried the Router useParams() hook? That might do the trick.

Also, if I understand your use-case correctly (e.g. enable components or states based on use being logged-in), you might be able to use isAuthenticated() for the logic. (Thoughts about this approach, @peterp?)

1 Like