Skip to content
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

Proposal: allow to ignore layout on config #94

Open
cjoecker opened this issue Dec 5, 2023 · 5 comments
Open

Proposal: allow to ignore layout on config #94

cjoecker opened this issue Dec 5, 2023 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@cjoecker
Copy link

cjoecker commented Dec 5, 2023

I have the following routes:
routes/app+/ui.tsx
routes/app+/ui-without-layout.tsx
routes/app+/_layout.tsx

In ui.tsx, I want to show the layout. In ui-without-layout.tsx, I don't want to show the layout.
Since both routes are inside the routes/app+ folder, the layout is shown on both routes.

I can hide the layout with a condition inside the react component of _layout.
But it will be nicer if I have the possibility in the remix.config of remix-flat-routes to ignore the layout.
Something like this:

{
	routes: async (defineRoutes) => {
		return flatRoutes("routes", defineRoutes, {
			ignoredLayouts: [
				{
					layout: "routes/app+/_layout.tsx",
					route: "routes/app+/ui-without-layout.tsx",
				},
			],
		});
	},
}
@kiliman
Copy link
Owner

kiliman commented Dec 5, 2023

With hybrid routes, there are some extended conventions.

As you know, app+/_layout.tsx is equivalent to app.tsx

And typically, you'd want all your child routes to use the parent layout. However to opt out of this, you would typically use the _ suffix. So in flat-files, you'd use app_.ui-without-layout.tsx.

To do the equivalent in hybrid routes, just name your child route with the _. prefix. This will append it to the parent route.

So app+/_.ui-without-layout.tsx is converted to app_.ui-without-layout.tsx which is what you ultimately want.

@kiliman
Copy link
Owner

kiliman commented Dec 5, 2023

See #58 for details. I should add this to the README.

@cjoecker
Copy link
Author

cjoecker commented Dec 5, 2023

@kiliman smart! Thanks for the explanation.

Would it make sense to have a cheat sheet in the documentation? I have this in the README of my project:

  1. Folders with _ prefix and + suffix like _auth+ are ignored in paths
  2. Files inside folders with + suffix are added to the path. E.g. account+/change-password.tsx becomes /account/change-password
  3. Files with _index.tsx prefix inside folders with + suffix are the default files for the path. E.g. account+/_index.tsx becomes /account.
  4. Files with _layout.tsx suffix are the layout files for the path. E.g. account+/_layout.tsx becomes the layout for all the paths inside /account
  5. Routes that should not show the _layout.tsx must have a _. prefix. E.g. account+/_.ui-witouth-layout.tsx do not show the layout inside account+ folder

Maybe it makes sense to reorganize the README since I feel it has grown historically and I tend to oversee parts of it. I can submit a PR for that if you want.

@kiliman
Copy link
Owner

kiliman commented Dec 5, 2023

Yes, I've been meaning to rewrite the README.

I want to highlight the differences between remix-flat-routes and the Remix v2 routing convention.

@dkAndFed
Copy link

dkAndFed commented Mar 6, 2024

On related note, how would one solve the following with the hybrid approach.

foo+/
├── _.bar_.baz_.qux+/      # Having to repeat the segments makes it difficult to maintain
│   ├── _route.tsx
│   └── quux.tsx
├── bar+/
│   ├── baz+/
│   │   ├── _.qux+/        # Will only escape `baz` layout but want to escape all the way to root
│   │   │   ├── _route.tsx
│   │   │   └── quux.tsx
│   │   └── _route.tsx
│   └── _route.tsx
└── _route.tsx

Perhaps it's possible to write some custom logic in the existing implementation with a custom annotator to ignore the layout up to a given segment? Perhaps something as follow 🤔

foo+/
├── bar+/
│   ├── baz+/
│   │   ├── ~3.qux+/        # Will escape layout of 3 ancestor segments and produce `foo_.bar_.baz_.qux`
│   │   │   ├── _route.tsx  # `foo_.bar_.baz_.qux._route`
│   │   │   └── quux.tsx    # `foo_.bar_.baz_.qux.quux`
│   │   └── _route.tsx
│   └── _route.tsx
└── _route.tsx

@mikkpokk mikkpokk added the documentation Improvements or additions to documentation label Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants