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

feat(router): Allow redirect routes to use route names as target #10376

Merged
merged 5 commits into from
Apr 2, 2024

Conversation

Tobbe
Copy link
Member

@Tobbe Tobbe commented Mar 30, 2024

When specifying a redirect route like <Route path="/simple" redirect="/newSimple" name="simple" /> the value of redirect is the path of the page the user should be redirected to. However, the paths can be long and annoying to type out. And if they ever change the redirect would now be broken.

Also, for private routes we do this:

<Router>
  <Route path="/" page={HomePage} name="home" />
  <PrivateSet unauthenticated="home">
    <Route path="/admin" page={AdminPage} name="admin" />
  </PrivateSet>
</Router>

Here, if a user isn't authenticated, the user will be redirected to the home route. Notice how the target route is specified by its name (home) instead of its path (/).

With this PR it's now also possible to redirect using the name of the target route, making our route behavior more consistent. So this will now work

<Router>
  <Route path="/" page={HomePage} name="home" />
  <Route path="/no-longer-exists" redirect="home" />
</Router>

Old style paths still works. The logic is super simple -> if the redirect value starts with / it's assumed to be a path. If not, it's assumed to be a route name. This should make this PR fully backwards compatible.

@Tobbe Tobbe marked this pull request as draft March 30, 2024 22:08
@Tobbe Tobbe added the release:feature This PR introduces a new feature label Mar 31, 2024
@Tobbe Tobbe added this to the next-release milestone Mar 31, 2024
@Tobbe Tobbe marked this pull request as ready for review April 2, 2024 08:26
@Tobbe Tobbe enabled auto-merge (squash) April 2, 2024 08:27
@Tobbe Tobbe merged commit 5c146f7 into redwoodjs:main Apr 2, 2024
46 checks passed
dac09 added a commit to dac09/redwood that referenced this pull request Apr 2, 2024
…nto feat/register-middleware

* 'feat/register-middleware' of github.com:dac09/redwood:
  feat(router): Allow redirect routes to use route names as target (redwoodjs#10376)
  chore(babel-config): switch to vitest (redwoodjs#10361)
  docs(redirect): Add docs for redirect routes (redwoodjs#10374)
  chore(changesets): Automatically find PR number (redwoodjs#10377)
  chore(deps): Upgrade `lru-cache` (redwoodjs#10378)
  chore(e2e): use tarsync for syncing framework state to project (redwoodjs#10379)
@Tobbe Tobbe deleted the tobbe-redirect-named-route branch April 2, 2024 12:12
@ahaywood ahaywood modified the milestones: next-release, v7.4.0 Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:feature This PR introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants