-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(react-router): navigate if redirect is thrown in component
- Loading branch information
1 parent
5c8c38a
commit adf8a33
Showing
12 changed files
with
327 additions
and
3 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
19 changes: 19 additions & 0 deletions
19
e2e/react-router/basic-file-based/src/routes/redirect/component/first.tsx
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,19 @@ | ||
import { createFileRoute, redirect } from '@tanstack/react-router' | ||
import React from 'react' | ||
|
||
export const Route = createFileRoute('/redirect/component/first')({ | ||
component: RouteComponent, | ||
}) | ||
|
||
function useThrowRedirect() { | ||
throw redirect({ to: '/redirect/component/second' }) | ||
} | ||
|
||
function RouteComponent() { | ||
useThrowRedirect() | ||
return ( | ||
<div data-testid="first"> | ||
<h1>Redirecting...</h1> | ||
</div> | ||
) | ||
} |
23 changes: 23 additions & 0 deletions
23
e2e/react-router/basic-file-based/src/routes/redirect/component/index.tsx
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,23 @@ | ||
import { Link, createFileRoute } from '@tanstack/react-router' | ||
|
||
export const Route = createFileRoute('/redirect/component/')({ | ||
component: RouteComponent, | ||
}) | ||
|
||
function RouteComponent() { | ||
return ( | ||
<div data-testid="first"> | ||
<Link | ||
from={Route.fullPath} | ||
to="./first" | ||
activeProps={{ | ||
className: 'font-bold', | ||
}} | ||
preload="intent" | ||
data-testid={'link'} | ||
> | ||
go to second | ||
</Link> | ||
</div> | ||
) | ||
} |
9 changes: 9 additions & 0 deletions
9
e2e/react-router/basic-file-based/src/routes/redirect/component/second.tsx
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,9 @@ | ||
import { createFileRoute } from '@tanstack/react-router' | ||
|
||
export const Route = createFileRoute('/redirect/component/second')({ | ||
component: RouteComponent, | ||
}) | ||
|
||
function RouteComponent() { | ||
return <div data-testid="second">Hello "/redirect/component/second"!</div> | ||
} |
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.