TanStack Router
Modern and scalable routing for React applications.
ReactLynx supports both Memory Routing
and File-Based Routing,
where Memory Routing is required due to browser History API limitations in Lynx,
and File-Based Routing is enabled through seamless @tanstack/router-plugin/rspack integration in Rspeedy.
Installation
Install dependencies:
Install devDependencies:
Project Configuration
- File-based Routing: Enabled via
@tanstack/router-plugin/rspackfor seamless routing integration. - React 18 API Compatibility: Use
@lynx-js/react/compatto ensure third-party libraries work correctly.
❓ Why use @lynx-js/react/compat
ReactLynx offers React 18 API compatibility via @lynx-js/react/compat,
providing crucial APIs such as React.startTransition required by TanStack
Router.
Router Configuration
In the Lynx environment, the document is undefined, causing the router to incorrectly identify it as isServer: true. You need to explicitly set isServer: false to ensure proper rendering.
Additionally, Memory Routing is required due to browser History API limitations in Lynx.
Polyfill
To ensure URLSearchParams API works correctly in the Lynx environment,
add url-search-params-polyfill at the top of your entry file:
File-Based
TanStack Router supports file-based routing where your file structure defines your routes.
Place your route components in the src/routes directory, with __root.tsx serving as the root component.
The @tanstack/router-plugin/rspack automatically scans the src/routes directory and generates a routeTree.gen.ts file
that contains all the route definitions and type information. This generated file includes:
- Route imports and configurations
- TypeScript interfaces for type-safe routing
- The complete route tree structure
See TanStack File-Based Routing for more details.
Example
