-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Description
TL;DR
All imports in routes.ts
and all its direct or transitive imports have to be absolute or relative using ./
and ../
notation, path aliases like ~
and @
aren't resolved correctly.
The issue
Vite and TypeScript allows defining aliases to relatively access files without using ./
or ../
notation, this is pretty significant for complex apps at scale as imports point to different, sometimes deeply nested files.
One of the usecases that inspired React Router's config-based route pattern and routes.ts
was this, for example if I want to make my apps modular or feature-based, I'd use high level folders to separate features, each of these feature might export their own routes, these routes need to be imported, and for the sake of readability and consistency, we use ~
or @
symbols as relative path aliases.
Also, sometimes, we need to import variables into the routes.ts
file, for example when you want to create a unique id for a route and you don't want to duplicate code and future-proof your app, this too, would be imported using an aliased path.
These use-cases aren't currently handled correctly when the routes.ts
is evaluated and executed.
Please checkout the #14090 and see the bug IRL
Reproduction
- Clone
remix-run/react-router
- Checkout
akamfoad:routes-path-alias-issue
branch - Run
pnpm i
cd playground/framework-spa
- Run
pnpm run dev
- You'll immediately get an error that
routes.ts
is invalid
System Info
N/A
Used Package Manager
pnpm
Expected Behavior
For the app to work seamlessly regardless of usage of import aliases.
Actual Behavior
Error: Route config in "routes.ts" is invalid.