S
SolidJS10mo ago
Grahf

Protected route dynamic route that has to match certain parameter

I have a dynamic route for a user. The file route looks like this: routes/(home)/user/[user]/(user).jsx It's protected so you can only navigate it to when logged in. BUT.... since it's a dynamic route you can go to like: http://localhost:3000/user/kdjfhdjkf and it will load the same page as http://localhost:3000/user/grahf I think I'd like the page to load if and only if the parameter mathes the current logged in users name. In the (user).jsx component should I just check if the logged in username equals the parameter? If it doesn't then redirect to '/'?
1 Reply
shogun2077
shogun207710mo ago
I think that would be the best way to handle that for now. You can make a component that you can use as a wrapper for those pages under the dynamic route that does the check... so that you don't need to write the same piece of code multiple times