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

[v6] default route redirects #7535

Closed
bokelley opened this issue Jul 31, 2020 · 1 comment
Closed

[v6] default route redirects #7535

bokelley opened this issue Jul 31, 2020 · 1 comment

Comments

@bokelley
Copy link

bokelley commented Jul 31, 2020

Hi there. We are trying to upgrade our product to v6, and are running into an issue with default routes. We have a component TradeScreen that displays trades for a certain date, and use the path /trades/:yyyy/:mm/ to get there. We also want the path /trades/ to route to the current year and month.

The naive approach to this was something like this:

<Routes>
  <Route path="/" element={<Navigate to={"/trades/" + year + "/" + month}/>}/>
</Routes>

This sort of works, but because <Navigate> uses an effect, it actually renders the page, then does the redirect.

I understand why this needs to be an effect, but I wonder if it would make sense to have a callback that we could use, like translatePath() where we could say "please route /trades as if it were /trades/2020/07". Or maybe there is just a routing table that we pass in with the original <Router>. That keeps the underlying component independent of this routing logic but doesn't force a client-side redirect.

Open to other approaches to this, but feels like we need something here. (Also, before you say "why don't you just make the default year/month in your component if nothing is passed... sure... but how about a simple case where I want to route / to /trades when the user logs in?)

@timdorr
Copy link
Member

timdorr commented Jul 31, 2020

Please see the discussion in #7267.

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

2 participants