Comments (9)
For more context, this bug report is part of this Discord thread.
The problem is that the router-cli (vite-plugin) incorrectly infers the routing structure of a layout route when it is nested in a parent route.
✅ When the layout route is defined at the root, it generates the route tree correctly. Example
src/routes
_layout.tsx
_layout/auth.login.tsx // generates the route /auth/login
_layout/auth.register.tsx // generates the route /auth/register
...
✅ It also works correctly when flat files are used.
src/routes
auth._layout.tsx
auth._layout.login.tsx // generates the route /auth/login
auth._layout.register.tsx // generates the route /auth/register
...
❌ However, when the layout is nested inside a parent folder is when stuff starts to break. Reproduction where stuff is broken
src/routes
auth/
_layout.tsx
_layout/login.tsx // generates the route /auth/layout/login
_layout/register.tsx // generates the route /auth/layout/register
...
✅ Weirdly enough, it works correctly if you define a route.tsx
and index.tsx
file within the auth route. Example
src/routes
auth/
route.tsx
index.tsx
_layout.tsx
_layout/login.tsx // generates the route /auth/login
_layout/register.tsx // generates the route /auth/register
...
🐞 My best guess is that this looks to be a bug with both the detection of layout routes and how file-routes get attached to the virtual routes.
from router.
I have the same issue, this is my folder structure:
I would expect _BankAccounts
to not be added to the URL while being used as a layout for everything under _BankAccounts/
. What actually happens is that /BankAccounts
gets added to the URL.
The generated code from routeTree.gen.ts
looks like this:
const ErpCompanyIdSettingsBankAccountsBankAccountsRoute =
ErpCompanyIdSettingsBankAccountsBankAccountsImport.update({
path: '/settings/bank-accounts/BankAccounts',
getParentRoute: () => ErpCompanyIdRoute,
} as any).lazy(() =>
import(
'./routes/erp/$companyId/settings/bank-accounts/_BankAccounts.lazy'
).then((d) => d.Route),
)
Edit:
✅ Weirdly enough, it works correctly if you define a
route.tsx
andindex.tsx
file within the auth route. Examplesrc/routes auth/ route.tsx index.tsx _layout.tsx _layout/login.tsx // generates the route /auth/login _layout/register.tsx // generates the route /auth/register ...
This does not seem to work in my case, I am using @tanstack/[email protected]
.
from router.
Is this issue really fixed? Still only works for me using the following structure recommended here, which feels hacky
from router.
can you please create a new issue?
from router.
Having this issue too. Nested layout routes are not working.
Projects and settings are inaccessible unless I move them out of the route. Pretty serious bug....... basically blocks development on this project.
The use case is that a protected route named _authenticated.workspace.$workspaceId
should always redirect to _authenticated.workspace.$workspaceId.projects
, but all inner routes need layouts too. So we need to be able to create a non-nested route _authenticated.workspace.$workspaceId_
that does the redirect, and a layout route _authenticated.workspace.$workspaceId._layout
.
This doesn't work at all.
Edit: we figured out a way to get what we wanted but it's seriously convoluted. We now have a _authenticated.workspace.$workspaceId
route that is both an <Outlet />
but also conditional redirect that checks pathname:
const { pathname } = useLocation()
workspaceId ??= activeWorkspaceId ?? Array.from(workspaceIds)[0]
if (pathname!.split("/").filter(Boolean).length <= 2 && workspaceId) {
return <Navigate to={`/workspace/${workspaceId}/projects`} />
}
from router.
Dev-tools needs an update. Gets confused about nested index routes:
Thank you for this btw! Was the only thing holding me back from using this library for our production project.
from router.
I think it might actually be a bug with the route id?
from router.
I think this is still broken? The tree gen isn't picking up on the _ in workspaceLayout
from router.
@alicantorun can you please provide a minimal example by forking one of the examples on stackblitz ?
please also explain which workaround you consider "hacky" and would like to avoid.
from router.
Related Issues (20)
- Can't git clone repo on Windows due to `?split.tsx` files HOT 3
- useRouteContext initially undefined HOT 3
- DOCS: Impossible to find something about defaultPendingComponent in docs HOT 4
- Context missing on route preload HOT 2
- Route component not showing
- Route.to becomes `undefined` after a HMR save HOT 3
- defaultPendingMinMs blocks the page on load HOT 2
- Throwing an error in a `beforeLoad` handler does not render error component
- Undefined context after redirect with wrapInSuspense at root route (introduced in 1.33.6) HOT 6
- Module '"@tanstack/react-router"' has no exported member 'PickAsRequired'. HOT 1
- aria-current=page attribute is returned for all links HOT 2
- The test does not work when rendering the router HOT 6
- File base subroutes regression HOT 4
- Context is undefined when search validation fails HOT 1
- Incorrect not found component being rendered HOT 3
- Overlapping Keys Cause Type Issues Using Experimental Intersection
- `Route.fullPath` is typed incorrectly when using path params HOT 8
- Undefined context after redirect HOT 5
- `beforeLoad` does not run when resetting from `errorComponent`
- `matchRoute` from `useMatchRoute` doesn't resolve TS type with pathless (layout) routes HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from router.