Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add relative=path option for url-relative routing (#9160)
* feat: add relative=path option for url-relative routing * add to native * Change useFormActon to use an options object API * add changeset
- Loading branch information
1 parent
4c190e3
commit 815e1d1
Showing
12 changed files
with
527 additions
and
25 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,27 @@ | ||
--- | ||
"react-router": patch | ||
"react-router-dom": patch | ||
"react-router-native": patch | ||
--- | ||
|
||
feat: add `relative=path` option for url-relative routing (#9160) | ||
|
||
Adds a `relative=path` option to navigation aspects to allow users to opt-into paths behaving relative to the current URL instead of the current route hierarchy. This is useful if you're sharing route patterns in a non-nested for UI reasons: | ||
|
||
```jsx | ||
// Contact and EditContact do not share UI layout | ||
<Route path="contacts/:id" element={<Contact />} /> | ||
<Route path="contacts:id/edit" element={<EditContact />} /> | ||
|
||
function EditContact() { | ||
return <Link to=".." relative="path">Cancel</Link> | ||
} | ||
``` | ||
|
||
Without this, the user would need to reconstruct the contacts/:id url using useParams and either hardcoding the /contacts prefix or parsing it from useLocation. | ||
|
||
This applies to all path-related hooks and components: | ||
|
||
- `react-router`: `useHref`, `useResolvedPath`, `useNavigate`, `Navigate` | ||
- `react-router-dom`: `useLinkClickHandler`, `useFormAction`, `useSubmit`, `Link`, `Form` | ||
- `react-router-native`: `useLinkPressHandler`, `Link` |
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
Oops, something went wrong.