-
-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow throwing external redirects
- Loading branch information
1 parent
a42deba
commit 6ff9169
Showing
37 changed files
with
850 additions
and
83 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
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
11 changes: 11 additions & 0 deletions
11
e2e/react-router/basic-file-based/src/routes/redirect/$target.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,11 @@ | ||
import { createFileRoute } from '@tanstack/react-router' | ||
import { z } from 'zod' | ||
|
||
export const Route = createFileRoute('/redirect/$target')({ | ||
params: { | ||
parse: z.object({ | ||
target: z.union([z.literal('internal'), z.literal('external')]), | ||
}).parse, | ||
stringify: (params) => ({ target: params.target }), | ||
}, | ||
}) |
26 changes: 26 additions & 0 deletions
26
e2e/react-router/basic-file-based/src/routes/redirect/$target/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,26 @@ | ||
import { Link, createFileRoute } from '@tanstack/react-router' | ||
|
||
export const Route = createFileRoute('/redirect/$target/')({ | ||
component: () => ( | ||
<div> | ||
<Link | ||
from={Route.fullPath} | ||
to="./via-beforeLoad" | ||
activeProps={{ | ||
className: 'font-bold', | ||
}} | ||
> | ||
via-beforeLoad | ||
</Link>{' '} | ||
<Link | ||
from={Route.fullPath} | ||
to="./via-loader" | ||
activeProps={{ | ||
className: 'font-bold', | ||
}} | ||
> | ||
via-loader | ||
</Link>{' '} | ||
</div> | ||
), | ||
}) |
13 changes: 13 additions & 0 deletions
13
e2e/react-router/basic-file-based/src/routes/redirect/$target/via-beforeLoad.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,13 @@ | ||
import { createFileRoute, redirect } from '@tanstack/react-router' | ||
|
||
export const Route = createFileRoute('/redirect/$target/via-beforeLoad')({ | ||
beforeLoad: ({ params: { target } }) => { | ||
if (target === 'internal') { | ||
throw redirect({ to: '/posts' }) | ||
} | ||
throw redirect({ | ||
href: 'http://example.com', | ||
}) | ||
}, | ||
component: () => <div>{Route.fullPath}</div>, | ||
}) |
13 changes: 13 additions & 0 deletions
13
e2e/react-router/basic-file-based/src/routes/redirect/$target/via-loader.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,13 @@ | ||
import { createFileRoute, redirect } from '@tanstack/react-router' | ||
|
||
export const Route = createFileRoute('/redirect/$target/via-loader')({ | ||
loader: ({ params: { target } }) => { | ||
if (target === 'internal') { | ||
throw redirect({ to: '/posts' }) | ||
} | ||
throw redirect({ | ||
href: 'http://example.com', | ||
}) | ||
}, | ||
component: () => <div>{Route.fullPath}</div>, | ||
}) |
Oops, something went wrong.