Replies: 5 comments 9 replies
-
I'm really looking forward to this enhancement, because it simplifies things and makes you more productive, especially when prototyping. Thank you for continuously improving Hilla ❤️ |
Beta Was this translation helpful? Give feedback.
-
An alternative approach for the directory structure has come up in discussions. The idea would be to not have a dedicated
Benefits of the alternative would be:
Benefits of the original would be:
|
Beta Was this translation helpful? Give feedback.
-
One feature that server-based routing can enable is serving different pages and metadata based on the landing URL. Required to make external links to apps display correctly in 3rd party systems. It might be implicit in the design, but it is easy to miss unless there is also a test case. |
Beta Was this translation helpful? Give feedback.
-
What I'm missing is the ability to pass the When a View is missing data from the state export default function MyView() {
const { state } = useLocation();
const navigate = useNavigate();
const hasAllDataInState = Boolean(state?.importantThing);
React.useEffect(() => {
if (!hasAllDataInState) {
navigate('/my-other-route'); // "you should call navigate() in a React.useEffect()"
return;
}
})
if (!hasAllDataInState) {
return null;
}
return (<pre>{JSON.stringify(state?.importantThing)}</pre>)
} moving the verification that all data is present, and the redirect-handling, into the loader would clean up the code of the view a lot and remove the need to duplicate code. |
Beta Was this translation helpful? Give feedback.
-
React Router v7 will drop File Based Routing - https://www.youtube.com/watch?v=fjTX8hQTlEc&t=726s (but keep backwards compatibility). They make some arguments against using file-based routing in the video. |
Beta Was this translation helpful? Give feedback.
-
We plan to introduce a new default way of configuring the router so that any file under
frontend/views/
is automatically registered as a route. Additionally, metadata about the views should be available both in Java and in TypeScript to enable automating Spring Security configuration or main menu population.Files
Any file with an appropriate
export default
insidefrontend/views/
is automatically registered with the router. The route for that view is based on the location of the file inside the views directory. As an example the view exported fromfrontend/views/foo/bar.tsx
get registered with the route/foo/bar
.In addition to that very simple file name convention, we also support some special cases:
_
are ignored.$index.tsx
is converted to/
so that e.g.frontend/views/foo/$index.tsx
has the route/foo/
.$layout.tsx
defines an intermediate layout component (React component containing an<Outlet />
as the default export) that will be used for all views in the same directory and all child directories. This corresponds to an intermediate level with the layout component aselement
in the React Router configuration.{name}.tsx
for views and{name}/
for directories define path parameters corresponding to:name
in React Router.{{name}}.tsx
for views and{{name}}/
for directories define optional path parameters corresponding to:name?
in React Router.{{...name}}.tsx
defines a catchall parameter which corresponds to/*
in React Router. Note that the name is ignored and the parameter will be available as*
in e.g.useParams()
due to the way React Router works.Declarative view configuration
There are things you might want to configure for a view that cannot be expressed only using file name conventions. To fill those needs, there is also a way of defining configuration in the view itself. This configurations need to be declared in a way that can be extracted at compile time so that the information can be made available also for server-side Java before the view is rendered. This is done by exporting a JSON5-parsable object literal as
config
from the same module.The title is by default shown as
<title>
in the browser and in the header section of the application's<AppLayout>
. If no title is defined, then the name of the exported function is used to define the title.In addition to
title
androlesAllowed
, theViewConfig
type also defines properties for things like controlling whether the view implementation loaded eagerly or lazily, defining a custom route for the view, and for defining the ordering in case an automatically populated main menu is used.Manual configuration
There might be cases where the declarative configuration is not flexible enough. For those cases, the application still has the possibility to maintains its own
routes.tsx
file similarly to today. The file-system based configuration approach is only a way of automating the routing configuration but the actual routing is still done is the same way as before.The structure of
routes.tsx
is thus something like this:Unified routing combined with Flow
Making metadata about Hilla views available for server-side Java does also make it possible to handle Hilla and Flow views in a unified way. In applications mixing both Flow and Hilla, it will for example be possible to automatically populate both Flow and Hilla views into a unified main menu.
Beta Was this translation helpful? Give feedback.
All reactions