-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added better detection for absolute urls in link component (#9994)
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 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,5 @@ | ||
--- | ||
"react-router-dom": patch | ||
--- | ||
|
||
Improved absolute url detection in `Link` component (now also supports `mailto:` urls) |
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 |
---|---|---|
|
@@ -128,6 +128,50 @@ describe("<Link> href", () => { | |
|
||
expect(renderer.root.findByType("a").props.href).toEqual("//remix.run"); | ||
}); | ||
|
||
test('<Link to="mailto:[email protected]"> is treated as external link', () => { | ||
let renderer: TestRenderer.ReactTestRenderer; | ||
TestRenderer.act(() => { | ||
renderer = TestRenderer.create( | ||
<MemoryRouter initialEntries={["/inbox/messages"]}> | ||
<Routes> | ||
<Route path="inbox"> | ||
<Route | ||
path="messages" | ||
element={<Link to="mailto:[email protected]" />} | ||
/> | ||
</Route> | ||
</Routes> | ||
</MemoryRouter> | ||
); | ||
}); | ||
|
||
expect(renderer.root.findByType("a").props.href).toEqual( | ||
"mailto:[email protected]" | ||
); | ||
}); | ||
|
||
test('<Link to="web+remix://somepath"> is treated as external link', () => { | ||
let renderer: TestRenderer.ReactTestRenderer; | ||
TestRenderer.act(() => { | ||
renderer = TestRenderer.create( | ||
<MemoryRouter initialEntries={["/inbox/messages"]}> | ||
<Routes> | ||
<Route path="inbox"> | ||
<Route | ||
path="messages" | ||
element={<Link to="web+remix://somepath" />} | ||
/> | ||
</Route> | ||
</Routes> | ||
</MemoryRouter> | ||
); | ||
}); | ||
|
||
expect(renderer.root.findByType("a").props.href).toEqual( | ||
"web+remix://somepath" | ||
); | ||
}); | ||
}); | ||
|
||
describe("in a dynamic route", () => { | ||
|
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