Replies: 2 comments 3 replies
-
You can't wrap your routes in anything under Switch. It directly reads the props of its children to do route matching. So it would treat |
Beta Was this translation helpful? Give feedback.
-
I'd like to follow up on this. Our team is also working with route guards (aka permission-based routes) and on v5 wrapping routes was the way to go for us. Since the v6 beta came out, we've had to pivot: now routes that need a guard get wrapped with an expression guard around them. So we went from: <Routes>
<Route path="/" element={<Home />} />
<RouteGuard perm="ADMIN" path="/admin" element={<Admin />} />
<RouteGuard app="FORUM" path="/forum" element={<Forum />} />
<RouteGuard app="FORUM" perm="MOD" path="/forum/moderation" element={<ForumMod />} />
</Routes> to using something like this: <Routes>
<Route path="/" element={<Home />} />
{hasApp('FORUM') && <Route path="/forum" element={<Forum />} />}
{hasApp('FORUM') && hasPerm('MOD') && <Route path="/forum/moderation" element={<ForumMod />} />}
</Routes> While functional, we found it much easier to read and write routes with the previous custom route component. Is there a new, semantic, more recommended way of achieving this? While the current approach works, it isn't as elegant/readable as the old one. |
Beta Was this translation helpful? Give feedback.
-
Hello !
I am working on restricted routes following certains conditions for our users and I would like to know if my current solution is good practice or not.
Or if this isn't a good practice, can I wrap my restricted routes in a
React.Fragment
?Beta Was this translation helpful? Give feedback.
All reactions