0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
Commit graph

79 commits

Author SHA1 Message Date
Manuel Schiller
9c81d5ac57
fix: handle beforeLoad throwing notFound correctly (#6811) 2026-03-04 21:34:28 +01:00
Flo
5f7e9e872b
test: add onRendered event coverage for param and search updates (#6794) 2026-03-01 18:43:11 +01:00
Flo
f58d457542
fix(react-router,solid-router,vue-router): correct preload triggers for "intent" option (#6747) 2026-02-24 13:48:43 +01:00
Flo
99e3025650
fix(react-router): keep relative link active when changing inherited param (#6689) 2026-02-18 09:56:01 +01:00
Lee
28b0e8b244
fix(router-core): fix handle AbortError logic when rapid navigation (#6426)
* fix(router-core): fix handle AbortError logic

Signed-off-by: leesb971204 <leesb971204@gmail.com>

* ci: apply automated fixes

* test: update expected store update count for preloaded async loaders

Signed-off-by: leesb971204 <leesb971204@gmail.com>

* refractor changes

* update tests to handle wait times more appropriately

* tighten up test - coderabbit nitpick

---------

Signed-off-by: leesb971204 <leesb971204@gmail.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Nico Lynzaad <nlynzaad@zylangroup.com>
2026-02-05 03:38:09 +02:00
Manuel Schiller
a894baa7bd
feat: pass routeId into context/beforeLoad (#6579)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2026-02-03 00:59:12 +01:00
Jason Xie
4814d4ef90
fix(router-core): use encodeURIComponent for splat route params (#6520)
* fix(router-core): use encodeURIComponent for splat route params

Use encodeURIComponent instead of encodeURI for splat route parameters
to properly encode spaces, plus signs, and other special characters.

This fixes an SSR redirect loop that occurs when:
1. User navigates to a splat route with encoded characters (e.g., %20)
2. TanStack Router decodes params with decodeURIComponent
3. When rebuilding URL, encodeURI doesn't encode spaces/special chars
4. URL mismatch triggers redirect loop (307 redirects)

encodeURIComponent properly encodes these characters, preventing the
mismatch while still preserving forward slashes as path separators.

* update tests to use correct encoding for splat params

* use encodePathParam for splat/catch-all

* perf(router-core): add early return for URL-safe splat values

Add performance optimization that skips the split/map/join operation
when splat values only contain URL-safe characters (alphanumeric,
dash, period, underscore, tilde, exclamation, forward slash).

This avoids unnecessary processing in the hot path for common cases.

* fix(router-core): encode whitespace in encodeNonAscii

Update encodeNonAscii to also encode whitespace characters (spaces, tabs, etc.)
in addition to non-ASCII characters. This fixes SSR redirect loops where:

1. Request URL contains encoded spaces: /path/file%20name.pdf
2. parseLocation decodes pathname: /path/file name.pdf
3. buildLocation calls encodeNonAscii but spaces weren't encoded
4. URL mismatch triggers redirect loop

Now encodeNonAscii properly encodes:
- Whitespace characters (spaces become %20)
- Non-ASCII/unicode characters (including emojis)

Other ASCII special characters (parentheses, brackets, etc.) are preserved
as they are valid in URL paths.

* refactor(router-core): use regex in encodeNonAscii like original

* refactor(router-core): rename encodeNonAscii to encodePathLikeUrl

Rename the function to better reflect its expanded responsibility of
encoding paths the same way new URL() would, including:
- Whitespace characters (spaces → %20, tabs → %09)
- Non-ASCII/Unicode characters (emojis, accented characters)

The old name 'encodeNonAscii' was misleading since the function now
encodes more than just non-ASCII characters.

---------

Co-authored-by: Nico Lynzaad <nlynzaad@zylangroup.com>
Co-authored-by: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com>
2026-01-26 23:53:20 +02:00
Flo
cfbbcd556c
refactor(router-core): skip URL constructor in buildLocation (#6447) 2026-01-24 11:42:55 +01:00
Flo
f054c0c921
fix: revert "refactor: don't reparse upon navigation (#6398)" (#6468)
Revert "refactor: don't reparse upon navigation (#6398)"

This reverts commit 6cbd96e357.
2026-01-23 16:50:10 +01:00
Flo
655496fc20
refactor(router-core): skip full matchRoutesInternal for Link's buildLocation, use simple getMatchedRoutes (#6445) 2026-01-22 23:24:56 +01:00
Manuel Schiller
6cbd96e357
refactor: don't reparse upon navigation (#6398) 2026-01-19 23:00:21 +01:00
Manuel Schiller
abb82160eb
fix: Commit context together with status to avoid race condition (#6407) 2026-01-18 01:01:03 +01:00
Lee
942f0ff937
fix(router-core): handle AbortError in router execution flow (#4570) 2026-01-07 22:55:00 +01:00
Flo
7b4dcee399
refactor(router-core): index routes have index nodes in the segment tree (#6171) 2025-12-21 16:32:19 +01:00
Manuel Schiller
f330532e08
fix: generalize hydration cleanup (#6118)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-12-17 01:18:47 +01:00
Manuel Schiller
20aac85d7f
fix: compare rewritten url to decide if server needs to redirect (#6072) 2025-12-12 20:28:58 +01:00
Manuel Schiller
06de1f6777 flaky tests 2025-12-10 00:44:41 +01:00
Manuel Schiller
e681a56f05
fix: commit route context (#6053)
Co-authored-by: Jakob Norlin <jakob.stahl91@gmail.com>
2025-12-09 21:17:36 +01:00
jihoon
c35f70ec3c
fix(router-core): useBlocker navigation issues for 404 pages and external URLs (#4917) 2025-11-23 01:29:13 +01:00
Flo
5e130d7ee1
refactor(router-core): interpolatePath skips optional segments w/ nullish param value (#5934) 2025-11-21 23:55:16 +01:00
Remi
37eb416963
fix(router-core): Catch errors thrown during hydrate (#5686) 2025-11-19 21:06:05 +01:00
Lee
6b235a7cec
fix: update error handling in MatchInner to access error data directly (#4746) 2025-11-19 19:46:29 +01:00
dt_emmy
fb0f069363
fix(router-core): Route with server function as loader that throws notFound crashes route on HMR #5763 (#5890) 2025-11-19 17:34:32 +01:00
Flo
f39eb9b832
refactor(router-core): Process routeTree into segment tree instead of flatRoutes [WIP] (#5722) 2025-11-15 13:45:02 +01:00
Nico Lynzaad
f1bd5c589c
refactor(router-core): use original nextTo path when building location in its route form (#5851)
* fixes and tests

* standardize params output for empty optional params

* finalize leave params tests

* leave wildcard is no longer required

* remove leaveParams altogether

* leave changes to optional param output handling for a separate PR

* cleanup

* resolve build errors and nitpick
2025-11-14 01:55:39 +02:00
Birk Skyum
7880ad7b46
fix(solid-start): navigation transitions (#5792) 2025-11-09 21:33:59 +01:00
Birk Skyum
01682c5dfb
fix(solid-router): use Solid.useTransition (#5801) 2025-11-09 19:52:29 +01:00
Birk Skyum
da770787fa
fix(solid-router): setting search params with 2 parallel navigate calls (#5797) 2025-11-09 16:09:18 +01:00
Ramy Ben Aroya
c857362929
fix(router-core): trigger abort signal when navigating away after pendingMs (#5777)
* fix(router): trigger loader abort signal when navigating away after pendingMs

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-11-08 01:37:07 +01:00
Nico Lynzaad
26f23faf13
refactor(router-core): consistent Unicode handling (#5736)
* add router-core fixes and update tests

* update react-router unit tests

* update react-router e2e tests

* update solid-router unit tests

* update solid-router e2e tests

* update test description

* rename function

* rename test as per codeRabbit nitpick

* test cleanup
2025-11-06 03:35:59 +02:00
Birk Skyum
76c4f614f2
fix(solid-router): implement navigation transitions (#5691) 2025-11-04 03:51:16 +01:00
Birk Skyum
2d338e0156
test(router): wait for nav to complete (#5744) 2025-11-03 20:24:04 +01:00
Birk Skyum
219b72cf4b
test(router): set notFoundComponent in statusCode test (#5742)
test(router): set notfound component in statusCode test
2025-11-03 19:54:27 +01:00
Birk Skyum
470f9b63bf
test(router): add waitFor for page navigation link/optional-path-params (#5741) 2025-11-03 19:33:43 +01:00
Birk Skyum
bd37f613ed
test(solid-router): align Matches to react (#5695) 2025-10-30 06:31:56 +01:00
Nico Lynzaad
915de641cd
refactor(router-core): more stable url decoding (#5663)
* add decode path segment util

* ensure navigation and browsing to path has same encoding/decoding

* add e2e tests

* add test recommendations

* nitpick

* minor enhancements

* build array once

* add additional unit and e2e tests

* remove react import from solid test

* nitpicks

* final nitpicks

* use history.push
2025-10-28 23:33:50 +02:00
Birk Skyum
08d78c1e2f
test(solid-router): un-skip link tests (#5621) 2025-10-26 00:26:37 +02:00
Birk Skyum
735c1e3384
test(solid-router): fix timing in loaders test (#5622) 2025-10-26 00:26:19 +02:00
Birk Skyum
f4a544f405
test(solid-router): sync unit tests from react-router (#5614) 2025-10-25 19:21:19 +02:00
Paul Sachs
3eccdebd0a
fix(router-core): add support for handling any kind of empty _splat consistently (#5510)
* Add support for handling any kind of empty _splat consistently

* Add navigate test for empty spat

* Added useNavigate test

* Added full trailingSlash options testing matrix

* Refactored the trailing slash cases

* export trailingSlashOptions from router-core

* replicate tests for solid

* ci: apply automated fixes

* fix test name interpolation

* correct waitFor usage

* fix eslint error

---------

Co-authored-by: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com>
Co-authored-by: Nico Lynzaad <nlynzaad@zylangroup.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-10-21 01:13:39 +02:00
Dominik Dorfmeister
b0d0b25045
fix(react-router,solid-router): top-level Matches should use pendingComponent on root route (#5495) 2025-10-17 19:19:03 +02:00
Edmo Lima
e974ee516d
fix(solid-router): make useLoaderDeps return Accessor for reactivity (#5348) 2025-10-07 01:42:53 +02:00
Lee
e52673bb03
fix(router): hash history links with target="_blank" generate incorrect URLs (#5242) 2025-09-29 21:29:54 +02:00
Manuel Schiller
32faee22da
feat: Start RC (#5189)
Co-authored-by: Nico Lynzaad <nlynzaad@zylangroup.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Tanner Linsley <tannerlinsley@users.noreply.github.com>
Co-authored-by: James Opstad <13586373+jamesopstad@users.noreply.github.com>
Co-authored-by: chorobin <chrishorobin@hotmail.com>
Co-authored-by: Tanner Linsley <tannerlinsley@gmail.com>
Co-authored-by: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: hokkyss <hokkyss2@gmail.com>
Co-authored-by: Philippe Serhal <philippe.serhal@gmail.com>
Co-authored-by: Jack Herrington <jherr@pobox.com>
Co-authored-by: Brenley Dueck <brenleydueck@gmail.com>
2025-09-23 11:34:54 -06:00
Lee
2c8d5ce61e
fix(router): respect target attribute on inner component (#5115) 2025-09-18 20:06:37 +02:00
Nico Lynzaad
b6a98805cc
fix(router-core): params.parse should run as minimally as possible (#5124)
resolves #5123 and adds checks to tests to ensure this runs as minimally
as possible

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Performance**
* Reuses existing route matches to reduce redundant param parsing and
stabilize navigation/loading behavior.
* **Tests**
* Updated tests to match the new postId param shape, navigation paths,
and parameter displays; added mocks to verify param parsing calls.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-09-11 17:07:28 +02:00
Nico Lynzaad
8f8f03fbdc
fix(router-core): parse _strictParams. (#5120)
with changing useParams to make use of _strictParams it became apparent
that _strictParams did not apply param parsing correctly. This PR
resolves that problem and hence useParams now return the parsed params
correctly.

This PR also adds unit tests in both react-router and solid-router to
test this expected result.

A separate PR has been created to merge into alpha (#5121)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- New Features
- Stricter route parameter parsing and validation with support for
custom parse/stringify.
- Clearer per-route parameter error reporting, with optional
throw-on-error behavior.
  - More consistent parameter values across nested routes and loaders.

- Tests
- Added integration tests validating useParams with nested routing,
custom param parsing/stringifying, and loader data in both React and
Solid routers.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-09-11 09:27:55 +02:00
Karolis Užkuraitis
4b792b923b
fix(solid-router): RouteProvider Wrap and Match InnerWrap support propagating context to their children (#5033)
Refactored a bit router options.Wrap and options.InnerWrap usage in
RouterProvider and Match components.
Now they will be able to provide context for their children components.

Added few tests for scenarios that were failing before.

Fixes #3744

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* New Features
* Consistent wrapper handling across routing so routed content and
pending states share the same wrapper/context without adding extra DOM
nodes.
* Exposed createMemoryHistory for memory-based routing in apps and
tests.

* Refactor
* Simplified suspense and wrapper handling for clearer, safer rendering
behavior.

* Tests
* Added tests verifying context propagation through wrappers and into
pending (fallback) states.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-29 21:24:38 +02:00
Nico Lynzaad
2df8e52ba0
fix(Relative routing): Default relative routing to current location (#4978)
When using relative routing we have 3 things to consider:

1) Is this relative to the current location? This is specifically
relevant for using `to="."` and `to=".."` in layout routes
2) Is this relative to the rendered route location?
3) Should this be relative to some other route in the tree

We have had a few issues where it hasn't been clear how relative routing
is applied in various scenarios, and where the application differs, for
example `to="."` and `to=".."` was treated differently.

This PR applies the following:
1) when no from path is specified, navigation is done from the current
location, this does not affect absolute paths but makes relative paths
more standardised.
2) other relative navigations require a from location to be specified.

This is achieved by setting Link and useNavigate to default to the
current active location instead of the rendered route location. This
also simplifies the logic in buildLocation as we no longer specifically
cater for `to="."`.

Included in this PR is the required changes to router-core
(buildLocation), react-router and solid-router (Link and useNavigate),
tests for both react-router and solid-router and an update to the docs
to clarify the usage.

This closes #4842

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added active-location hooks, origin-aware navigation helpers,
programmatic Route API for Link generation, browser-history utilities,
optional from origin for Navigate, and route fullPath exposure.

* **Bug Fixes**
* More deterministic relative navigation (., ..) resolution,
preservation of search/params, and runtime warnings for invalid origins.

* **Documentation**
  * Clarified relative-link semantics and updated examples.

* **Tests**
* Vastly expanded end-to-end coverage for relative navigation, masking,
basepath, and trailing-slash permutations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-26 19:30:31 +02:00
Flo
642964e4e3
refactor(router-core): reduce buildLocation object allocations (#4981)
When we can (and it's reasonable), it's always beneficial to reduce the
number of objects we create in JS, so as to minimize the memory pressure
and the GC work.

`buildLocation` gets called pretty often, so removing a few object
allocations can be very beneficial (especially inside loops).

Also, from a purely "immediate performance" point of view,
`Object.assign` tends to be faster than `{...foo}`.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Refactor**
* Route parameter and search handling now use in-place updates to reduce
allocations and streamline iteration/control flow; behavior and public
API remain unchanged.
* **Tests**
* Updated tests to capture cloned parameter objects and assert on exact
values rather than relying on mock call history, preventing
mutation-related flakiness.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2025-08-17 18:35:45 +02:00