Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regexp routes redirecting #31

Open
ivan-suhorukov opened this issue Mar 5, 2024 · 5 comments
Open

Regexp routes redirecting #31

ivan-suhorukov opened this issue Mar 5, 2024 · 5 comments

Comments

@ivan-suhorukov
Copy link

ivan-suhorukov commented Mar 5, 2024

Now, when i use a RegExp routes, i cannot use openPage or redirectPage functions. Router throws RegExp routes are not supported. So may be we can support this by adding second converter to route? Something like this:

export const $router = createRouter({
  profile: [/\/(student|teacher|manager)\/profile/, (urlRole) => { return { role: urlRole }}, (urlRole) => `/${urlRole}/profile`],
                                                                                 where it is  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
})

So router can determine the redirect url and do redirect?

@ai
Copy link
Member

ai commented Mar 5, 2024

Is it better just pass URL to router.open(url)?

Defining function looks like pretty complex thing.

@ivan-suhorukov
Copy link
Author

ivan-suhorukov commented Mar 6, 2024

router.open(url) uses hard-coded url`s, so maybe better to user $router as a one source of truth?

When i change the route then, i dont need to change all of the router.open(url) calls.

@ai
Copy link
Member

ai commented Mar 6, 2024

When i change the route then, i dont need to change all of the router.open(url) calls.

Do you really often change URLs?

We can add this feature, let’s see how many bytes it takes and how it will affect complexity of types and logic.

@schwiet
Copy link

schwiet commented Aug 22, 2024

What is the recommended workaround? It seems that I can't use regexp routes if I want to do any redirects to that route. In my case the route with a regexp is my default route, so I redirect any invalid route to it.

@ai
Copy link
Member

ai commented Aug 22, 2024

@schwiet just use router.open() with manually written URL.

If you want to change API you need to help and send PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants