-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Pathless Layout Routes #19
Comments
After tinkering with the code, I was able to find a solution to Pathless Layout Routes that suited my needs. Update the patterns array to include a const patterns = {`
route: [/\/src\/pages\/|\.(jsx|tsx)$/g, ""],
splat: [/\[\.{3}.+\]/, "*"],
param: [/\[([^\]]+)\]/g, ":$1"],
pathless: [/~\//g, "/"],
slash: [/index|\./g, "/"],
} as const; Update segments in const segments = key
.replace(...patterns.route)
.replace(...patterns.splat)
.replace(...patterns.param)
.replace(...patterns.pathless)
.split("/"); Essentially, I'm assigning every "~" directory the value of empty string for it's path. An example folder structure may look like...
Where the generated routes would be
Any feedback on if this is viable? Or, am I missing an edge-case now that I've removed the Boolean filter. |
Hey @locchuong, I'm very glad to hear that! I think omitting the empty strings filtering will introduce issues as not all empty strings are necessarily a pathless layout. The other issue would be if you have multiple pathless layouts if I understand correctly, all would go under one empty string, which again will not be desirable. |
i am facing this issue at the moment and would be most grateful for a solution.. need to have routes like login, register, etc to have their own "auth" layout, adding a directory and a _layout file works but would be great if i didnt have to add directories(and by extension url paths) to get separate layout. Also, a root level layout, i have tried adding a _layout file to the pages directory itself and basically give all routes(except like auth routes above) a general layout, but this does not work, when i do that nothing renders..work around i came up with is to use _app to conditionally add or remove layout globally and to auth routes, based on pathname. how can i get around this? |
Support for pathless layout groups is now added at v1.6.14 @monarcode You can now define multiple pathless layouts, here's an example: src/pages/
├── (app)/
│ ├── _layout.tsx
│ ├── home.tsx /home wrapped by (app)/_layout.tsx
│ └── profile.tsx /profile wrapped by (app)/_layout.tsx
├── (auth)/
│ ├── _layout.tsx
│ ├── login.tsx /login wrapped by (auth)/_layout.tsx
│ └── register.tsx /register wrapped by (auth)/_layout.tsx
└── admin/
├── _layout.tsx
└── index.tsx /admin wrapped by admin/_layout.tsx Something to avoid tho, is to have duplicate routes in two different pathless layout groups for example Lastly for root level layout, you should only use Hope that helps! |
Pathless Layouts are quite useful when implementing an Auth / Private Layer to specific routes without prefixing routes with, say, "/auth". This feature comes with Remix through prefixing directories with a double-underscore, although I'm aware that that may be confusing since single-underscoring ignores directories/files. Any thoughts about adding this?
Remix Documentation: https://remix.run/docs/en/v1/guides/routing#pathless-layout-routes
Thanks in advance! It's been a pleasure using your library :)
The text was updated successfully, but these errors were encountered: