T
TanStack16mo ago
ambitious-aqua

Use explicit params on loader function

I have a pathless route of "/_layoutMain" which is basically my layout. Now I also have a "/channels/$guildId" route. But In the loader of "/_layoutMain" I need to get the "$guildId" of "/channels" But the loader param object is now type of Record<never, string> So I can't convince it that there is indeed a param here.
/_layoutMain
/channels/$guildId <- get this param from _layoutMain loader
/_layoutMain
/channels/$guildId <- get this param from _layoutMain loader
1 Reply
other-emerald
other-emerald16mo ago
afaik, this is not possible. the loader of /_layoutMain can also run on pages that have no $guildId, for example, when you have this setup:
/_layoutMain
/channels/$guildId
/foo
/_layoutMain
/channels/$guildId
/foo
now the loader of the layout will run for /foo, but there is no $guildId param. Best bet is to to a type assertion and then handle cases where the id exists and where it doesn't. The better fix is to use the loader of something that knows that the guildId really exists

Did you find this page helpful?