-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tobbe-nav-link-wording
- Loading branch information
Showing
4 changed files
with
114 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
- feat(router): Allow redirect routes to use route names as target (#10376) by @Tobbe | ||
|
||
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: | ||
```jsx | ||
<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 | ||
|
||
```jsx | ||
<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 change fully backwards compatible. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters