Skip to content

Commit d29c724

Browse files
committed
feat: add route and tests for handling pipe character in path
1 parent 6d1ae3e commit d29c724

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

e2e/react-start/basic/src/routeTree.gen.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import { Route as RawStreamSsrMixedRouteImport } from './routes/raw-stream/ssr-m
4242
import { Route as RawStreamSsrBinaryHintRouteImport } from './routes/raw-stream/ssr-binary-hint'
4343
import { Route as RawStreamClientCallRouteImport } from './routes/raw-stream/client-call'
4444
import { Route as PostsPostIdRouteImport } from './routes/posts.$postId'
45+
import { Route as PipeReferenceRouteImport } from './routes/pipe.$reference'
4546
import { Route as NotFoundViaLoaderRouteImport } from './routes/not-found/via-loader'
4647
import { Route as NotFoundViaBeforeLoadRouteImport } from './routes/not-found/via-beforeLoad'
4748
import { Route as MultiCookieRedirectTargetRouteImport } from './routes/multi-cookie-redirect/target'
@@ -228,6 +229,11 @@ const PostsPostIdRoute = PostsPostIdRouteImport.update({
228229
path: '/$postId',
229230
getParentRoute: () => PostsRoute,
230231
} as any)
232+
const PipeReferenceRoute = PipeReferenceRouteImport.update({
233+
id: '/pipe/$reference',
234+
path: '/pipe/$reference',
235+
getParentRoute: () => rootRouteImport,
236+
} as any)
231237
const NotFoundViaLoaderRoute = NotFoundViaLoaderRouteImport.update({
232238
id: '/via-loader',
233239
path: '/via-loader',
@@ -343,6 +349,7 @@ export interface FileRoutesByFullPath {
343349
'/multi-cookie-redirect/target': typeof MultiCookieRedirectTargetRoute
344350
'/not-found/via-beforeLoad': typeof NotFoundViaBeforeLoadRoute
345351
'/not-found/via-loader': typeof NotFoundViaLoaderRoute
352+
'/pipe/$reference': typeof PipeReferenceRoute
346353
'/posts/$postId': typeof PostsPostIdRoute
347354
'/raw-stream/client-call': typeof RawStreamClientCallRoute
348355
'/raw-stream/ssr-binary-hint': typeof RawStreamSsrBinaryHintRoute
@@ -389,6 +396,7 @@ export interface FileRoutesByTo {
389396
'/multi-cookie-redirect/target': typeof MultiCookieRedirectTargetRoute
390397
'/not-found/via-beforeLoad': typeof NotFoundViaBeforeLoadRoute
391398
'/not-found/via-loader': typeof NotFoundViaLoaderRoute
399+
'/pipe/$reference': typeof PipeReferenceRoute
392400
'/posts/$postId': typeof PostsPostIdRoute
393401
'/raw-stream/client-call': typeof RawStreamClientCallRoute
394402
'/raw-stream/ssr-binary-hint': typeof RawStreamSsrBinaryHintRoute
@@ -441,6 +449,7 @@ export interface FileRoutesById {
441449
'/multi-cookie-redirect/target': typeof MultiCookieRedirectTargetRoute
442450
'/not-found/via-beforeLoad': typeof NotFoundViaBeforeLoadRoute
443451
'/not-found/via-loader': typeof NotFoundViaLoaderRoute
452+
'/pipe/$reference': typeof PipeReferenceRoute
444453
'/posts/$postId': typeof PostsPostIdRoute
445454
'/raw-stream/client-call': typeof RawStreamClientCallRoute
446455
'/raw-stream/ssr-binary-hint': typeof RawStreamSsrBinaryHintRoute
@@ -494,6 +503,7 @@ export interface FileRouteTypes {
494503
| '/multi-cookie-redirect/target'
495504
| '/not-found/via-beforeLoad'
496505
| '/not-found/via-loader'
506+
| '/pipe/$reference'
497507
| '/posts/$postId'
498508
| '/raw-stream/client-call'
499509
| '/raw-stream/ssr-binary-hint'
@@ -540,6 +550,7 @@ export interface FileRouteTypes {
540550
| '/multi-cookie-redirect/target'
541551
| '/not-found/via-beforeLoad'
542552
| '/not-found/via-loader'
553+
| '/pipe/$reference'
543554
| '/posts/$postId'
544555
| '/raw-stream/client-call'
545556
| '/raw-stream/ssr-binary-hint'
@@ -591,6 +602,7 @@ export interface FileRouteTypes {
591602
| '/multi-cookie-redirect/target'
592603
| '/not-found/via-beforeLoad'
593604
| '/not-found/via-loader'
605+
| '/pipe/$reference'
594606
| '/posts/$postId'
595607
| '/raw-stream/client-call'
596608
| '/raw-stream/ssr-binary-hint'
@@ -642,6 +654,7 @@ export interface RootRouteChildren {
642654
Char45824Char54620Char48124Char44397Route: typeof Char45824Char54620Char48124Char44397Route
643655
ApiUsersRoute: typeof ApiUsersRouteWithChildren
644656
MultiCookieRedirectTargetRoute: typeof MultiCookieRedirectTargetRoute
657+
PipeReferenceRoute: typeof PipeReferenceRoute
645658
RedirectTargetRoute: typeof RedirectTargetRouteWithChildren
646659
MultiCookieRedirectIndexRoute: typeof MultiCookieRedirectIndexRoute
647660
RedirectIndexRoute: typeof RedirectIndexRoute
@@ -882,6 +895,13 @@ declare module '@tanstack/react-router' {
882895
preLoaderRoute: typeof PostsPostIdRouteImport
883896
parentRoute: typeof PostsRoute
884897
}
898+
'/pipe/$reference': {
899+
id: '/pipe/$reference'
900+
path: '/pipe/$reference'
901+
fullPath: '/pipe/$reference'
902+
preLoaderRoute: typeof PipeReferenceRouteImport
903+
parentRoute: typeof rootRouteImport
904+
}
885905
'/not-found/via-loader': {
886906
id: '/not-found/via-loader'
887907
path: '/via-loader'
@@ -1184,6 +1204,7 @@ const rootRouteChildren: RootRouteChildren = {
11841204
Char45824Char54620Char48124Char44397Route,
11851205
ApiUsersRoute: ApiUsersRouteWithChildren,
11861206
MultiCookieRedirectTargetRoute: MultiCookieRedirectTargetRoute,
1207+
PipeReferenceRoute: PipeReferenceRoute,
11871208
RedirectTargetRoute: RedirectTargetRouteWithChildren,
11881209
MultiCookieRedirectIndexRoute: MultiCookieRedirectIndexRoute,
11891210
RedirectIndexRoute: RedirectIndexRoute,

e2e/react-start/basic/src/routes/__root.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@ function RootDocument({ children }: { children: React.ReactNode }) {
181181
>
182182
Raw Stream
183183
</Link>{' '}
184+
<Link
185+
to="/pipe/$reference"
186+
params={{ reference: 'hello|world' }}
187+
activeProps={{
188+
className: 'font-bold',
189+
}}
190+
>
191+
Dynamic Pipe Character
192+
</Link>
184193
<Link
185194
// @ts-expect-error
186195
to="/this-route-does-not-exist"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/pipe/$reference')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
return <h4>Hello {params.reference}!</h4>
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect } from '@playwright/test'
2+
3+
import { test } from '@tanstack/router-e2e-utils'
4+
5+
test('encodes pipe character in href for param link', async ({ page }) => {
6+
await page.goto('/pipe/hello|world')
7+
8+
await expect(page.locator('body')).toContainText('Hello hello|world!')
9+
})
10+
11+
test('direct navigation keeps encoded url after reload', async ({
12+
page,
13+
baseURL,
14+
}) => {
15+
await page.goto('/pipe/hello|world')
16+
17+
await expect(page.locator('body')).toContainText('Hello hello|world!')
18+
expect(page.url()).toBe(`${baseURL}/pipe/hello%7Cworld`)
19+
20+
await page.reload()
21+
22+
await expect(page.locator('body')).toContainText('Hello hello|world!')
23+
expect(page.url()).toBe(`${baseURL}/pipe/hello%7Cworld`)
24+
})

0 commit comments

Comments
 (0)