hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Add feature for rendering an FS router view outside the main layout

Open Legioth opened this issue 1 year ago • 4 comments
trafficstars

Describe your motivation

Some special views, such as a login view, might need to be rendered without any wrapping layout. The way of doing this right now is to copy generated/routes.tsx and customize it but this is not very convenient.

Describe the solution you'd like

Add a property to ViewConfig specifically for this case.

export const config: ViewConfig = {
  skipLayouts: true,
  menu: { exclude: true }
}

Describe alternatives you've considered

  • There has been an idea to add a property to ViewConfig that would allow defining an arbitrary layout (or no layout at all) for a view. This would be relatively complex to map to the React Router configuration structure which is why I instead suggest defining a shorthand specifically for having no layout at all.
  • There has been an idea to add support for @phantom/ directory that would have its own layout without contributing to the path. This would map almost directly to the React Router configuration structure but it would also mean that the filesystem structure wouldn't match the URL structure and you would have to move around all existing views if you want to make one view skip the layout.

The suggested skipLayouts property could remain as a shorthand even if we implement either of the more flexible alternatives later on.

Additional context

No response

Legioth avatar May 06 '24 08:05 Legioth

Should it be named skipLayouts to make clear that it will skip all layouts?

cromoteca avatar May 07 '24 12:05 cromoteca

@Route has an option autoLayout that allows to opt-out a Flow route from @Layout. Would be great to extend this option for the case, when one wants to have Flow Login view and don't want it to be rendered in the Hilla's main layout.

I think the naming should be the same, either autoLayout or skipLayouts in both @Route and ViewConfig.

mshabarov avatar Oct 10 '24 07:10 mshabarov

@mshabarov would be nice to have the names match, but before that we should agree on the usage. How does autoLayout work, does it default to true as the name suggests, so that users have to declare autoLayout = false to opt-out? If so, that's a bit problematic in JS context, where a missing object keys default to falsy undefined. Would skipLayouts name and approach work in Flow context?

platosha avatar Oct 10 '24 08:10 platosha

skipLayouts would work IMO. It is used in just one place in Java. If we are confident with the name, we should perhaps change it from autoLayout to skipLayout in 24.5 for better consistency in future.

mshabarov avatar Oct 10 '24 11:10 mshabarov