Skip to content

Add ssrPathname prop for SSR path-based route matching#99

Merged
uhyo merged 3 commits intomasterfrom
claude/ssr-path-specification-tx3pA
Feb 17, 2026
Merged

Add ssrPathname prop for SSR path-based route matching#99
uhyo merged 3 commits intomasterfrom
claude/ssr-path-specification-tx3pA

Conversation

@uhyo
Copy link
Owner

@uhyo uhyo commented Feb 17, 2026

When ssrPathname is provided, the Router uses it to match path-based
routes during SSR instead of only matching pathless routes. Loaders
are still skipped during SSR. Once the client hydrates, the real URL
from the Navigation API takes over and ssrPathname is ignored.

https://claude.ai/code/session_01GFC4bkwjrJwBJzqrQxK77n

When ssrPathname is provided, the Router uses it to match path-based
routes during SSR instead of only matching pathless routes. Loaders
are still skipped during SSR. Once the client hydrates, the real URL
from the Navigation API takes over and ssrPathname is ignored.

https://claude.ai/code/session_01GFC4bkwjrJwBJzqrQxK77n
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new ssrPathname prop to the Router component to enable path-based route matching during server-side rendering (SSR). Previously, only pathless routes could match during SSR. With this prop, developers can specify a pathname that the router uses to match path-based routes during SSR, while loaders remain skipped. Once the client hydrates, the Navigation API takes over and the ssrPathname is ignored.

Changes:

  • Added ssrPathname optional prop to Router component with comprehensive JSDoc documentation
  • Modified route matching logic to use ssrPathname ?? null when locationEntry is unavailable during SSR
  • Added comprehensive test suite with 8 test cases covering various scenarios including nested routes, params extraction, and loader behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/router/src/Router.tsx Added ssrPathname prop definition with documentation, updated route matching logic to use ssrPathname during SSR, and added ssrPathname to useMemo dependency array
packages/router/src/tests/fallback.test.tsx Added comprehensive test suite for ssrPathname feature covering path matching, nested routes, params, loaders, and edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Routes with loaders are now excluded from matching during SSR (when
ssrPathname is provided). This preserves type safety since loader data
is unavailable during SSR. When all children of a route have loaders,
the parent renders as an SSR shell instead.

Added skipLoaders option to matchRoutes and corresponding unit tests.

https://claude.ai/code/session_01GFC4bkwjrJwBJzqrQxK77n
The pathname === null checks in matchRoute already handle loader
skipping, so skipLoaders: true is redundant but clearer in that case.

https://claude.ai/code/session_01GFC4bkwjrJwBJzqrQxK77n
@uhyo uhyo merged commit 98ac315 into master Feb 17, 2026
1 check passed
@uhyo uhyo deleted the claude/ssr-path-specification-tx3pA branch February 17, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants