Skip to content

Commit ecd79d2

Browse files
authored
fix(router-core): Non nested paths - only strip trailing underscore on route segments (#5182)
as part of #5169 we made changes to strip underscores from the paths to ensure it is dealt with correctly during parsing. inadvertently this stripped it from not only the route segments but also the base segments. This PR resolves that issue by making `baseParsePathName` aware which type of segments it is parsing. a new optional boolean paramater, ```basePathValues```, is introduced in `baseParsePathName` and `parsePathname` to allow this distinction between routeSegments and/or basesegments to be passed on to `baseParsePathName`. 2 new functions are introduced `parseBasePathSegments` and `parseRoutePathSegments`, which is just wrapper functions around `parsePathname`, but ensures clearer understanding of what set of parsing instructions is applied and `basePathValues `is set correctly based on the requirement. updated the unit tests to take into account the need not to strip the base values and also enhanced the e2e tests as well to ensure more through testing with different usages. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added non-nested route demos (named, prefix, suffix, path) with index/foo/bar pages and updated navigation in React and Solid examples. - Bug Fixes - Improved path parsing/matching to handle non-nested segments, prefixes/suffixes and trailing underscores; refined route sorting/resolution. - Tests - Added comprehensive E2E coverage for non-nested paths; removed obsolete baz-based tests. - Expanded unit tests for path interpolation and matching (underscore, prefix/suffix cases). <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0d00f28 commit ecd79d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2494
-370
lines changed

e2e/react-router/basic-file-based/src/routeTree.gen.ts

Lines changed: 504 additions & 66 deletions
Large diffs are not rendered by default.

e2e/react-router/basic-file-based/src/routes/non-nested/baz.$bazid.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

e2e/react-router/basic-file-based/src/routes/non-nested/baz.tsx

Lines changed: 0 additions & 14 deletions
This file was deleted.

e2e/react-router/basic-file-based/src/routes/non-nested/baz_.$bazid.edit.tsx

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/named/$baz/foo')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
10+
return (
11+
<div>
12+
<div data-testid="non-nested-named-baz-foo-heading">
13+
Hello nested named baz foo page
14+
</div>
15+
<div data-testid="non-nested-named-baz-foo-param">
16+
{JSON.stringify(params)}
17+
</div>
18+
</div>
19+
)
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/named/$baz/')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
return (
10+
<div>
11+
<div data-testid="non-nested-named-baz-index-heading">
12+
Hello nested named baz index
13+
</div>
14+
<div data-testid="non-nested-named-baz-index-param">
15+
{JSON.stringify(params)}
16+
</div>
17+
</div>
18+
)
19+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Outlet, createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/named/$baz')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
return (
9+
<div>
10+
<div data-testid="non-nested-named-baz-route-heading">
11+
Hello non-nested named baz route layout
12+
</div>
13+
<Outlet />
14+
</div>
15+
)
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/named/$baz_/bar')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
return (
10+
<div>
11+
<div data-testid="non-nested-named-baz-bar-heading">
12+
Hello non-nested named bar
13+
</div>
14+
<div data-testid="non-nested-named-baz-bar-param">
15+
{JSON.stringify(params)}
16+
</div>
17+
</div>
18+
)
19+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/named')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
return (
9+
<div>
10+
<div data-testid="non-nested-named-root-route-heading">
11+
Hello non-nested named layout
12+
</div>
13+
<div>
14+
<Link
15+
from={Route.fullPath}
16+
to="./$baz"
17+
params={{ baz: 'baz' }}
18+
data-testid="to-named-index"
19+
>
20+
To named index
21+
</Link>
22+
<Link
23+
from={Route.fullPath}
24+
to="./$baz/foo"
25+
params={{ baz: 'baz' }}
26+
data-testid="to-named-foo"
27+
>
28+
To named foo
29+
</Link>
30+
<Link
31+
from={Route.fullPath}
32+
to="./$baz/foo"
33+
params={{ baz: 'baz_' }}
34+
data-testid="to-named-foo-2"
35+
>
36+
To named foo 2
37+
</Link>
38+
<Link
39+
from={Route.fullPath}
40+
to="./$baz/bar"
41+
params={{ baz: 'baz' }}
42+
data-testid="to-named-bar"
43+
>
44+
To named bar
45+
</Link>
46+
<Link
47+
from={Route.fullPath}
48+
to="./$baz/bar"
49+
params={{ baz: 'baz_' }}
50+
data-testid="to-named-bar-2"
51+
>
52+
To named bar 2
53+
</Link>
54+
</div>
55+
<Outlet />
56+
</div>
57+
)
58+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
3+
export const Route = createFileRoute('/non-nested/path/baz/foo')({
4+
component: RouteComponent,
5+
})
6+
7+
function RouteComponent() {
8+
const params = Route.useParams()
9+
10+
return (
11+
<div>
12+
<div data-testid="non-nested-path-baz-foo-heading">
13+
Hello nested path baz foo page
14+
</div>
15+
<div data-testid="non-nested-path-baz-foo-param">
16+
{JSON.stringify(params)}
17+
</div>
18+
</div>
19+
)
20+
}

0 commit comments

Comments
 (0)