qwik
qwik copied to clipboard
Typesafe router[✨]
Is your feature request related to a problem?
Hello, I was trying to type my routeLoader$
where I use params
and found out, that I can't. It's not automatic nor can I use generic. What I ended up with is assertion via unknown
which is not a good solution.
type RouteParams = {
id: string;
};
export const use_get_movie = routeLoader$(async ({ params }) => {
const response = await get_movie((params as unknown as RouteParams).id);
return response.data;
});
Describe the solution you'd like
It would be awesome to have it automatically typed. Since it's file based, when I have a folder [id]
it should be able to know, that id
is a param
that is a string
Another feature that would be great is typed <Link>
component. That if I start typing in href
attribute, it would suggest all the routes that are available in the project.
Describe alternatives you've considered
Inspiration could be Tanstack Router although there is a different API. But Next.js router has typed Link
component, and I believe it's a similar router to Qwik router, since it's file based. So it should be possible.
Additional context
Version:
"@builder.io/qwik": "0.103.0",
"@builder.io/qwik-city": "0.103.0",