13

I know react-router-dom v6 is in beta but I'm playing with it and have a couple of questions about useRoutes() & path & regex.

BTW - v6 looks great!!

Before in v4 I would do the following. It would only match if the path was /profile/<10 digit number>.... (no is profile_id). Is there a way to regex url's like this in v6?

<Route path="/profile/:userid([0-9]{10})" component={Profile} />

Also in V4 I was able to limit the Param options after the param in brackets - ':type(email|forgot)'. Is there way to do this in v6?

<Route exact path="/login/:type(email|forgot)" component={Login} />

My attempts below where not successful.

{ path: '/profile/:userid([0-9]{10})', element: <Profile /> }

{ path: '/login/:type(email|forgot)', element: <Login /> }

I know with the second one (email|forgot) I can use 'children' and this is fine. I just wanted to ask.

Its the profile_id 10 digit regex that would be great. Would rather not route to the component if that condition isn't met.

any info would be good. thankyou very much!!

1 Answer 1

18

I wrote directly to the React Router V6 Development team and currently regex isn't supported in path. There is a small chance it might be added...

Here is the response - https://github.com/remix-run/react-router/discussions/8132

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.