0

I want to access the URL parameters with useLocation() in a routeLoader$():

export const useRouteLoader = routeLoader$(
  (requestEvent: RequestEvent) => {
    const loc = useLocation();
    console.log(loc.params);
    //Other code
  }
);

But it does not work. I want to log the URL params to the console. How do i do that?

Kristóf Göncző
  • 382
  • 1
  • 5
  • 16

1 Answers1

1

You cannot use useLocation() in routeLoader$()s, but routeLoader$ has access to the RequestEvent API which includes information about the current HTTP request, including the URL params.

export const useRouteLoader = routeLoader$((requestEvent) => {
  console.log(requestEvent.params);
  //Other code
});

See more about routeLoader$() at routeLoader$() Qwik City documentation.

See what the RequestEvent contains at RequestEvent Qwik City documentation.

Kristóf Göncző
  • 382
  • 1
  • 5
  • 16