#How can i determine the _data parameter of a route by it's pathname?
1 messages · Page 1 of 1 (latest)
I don't understand what you're asking.. can you give an example?
let's say that I have a route /blog/posts/2 in a file routes/blog.posts.$id.tsx
When navigating to this route client side remix is making a request to /blog/posts/2?_data=routes/blog.posts.$id.
I need to determine this url (with the _data param) by the pathname.
Gotcha.. you can inspect the window.__remixManifest variable.. it's an object keyed by id (routes/blog.posts.$id) and you'll find a path property (blog/posts/:id)
The route ID (what you see in _data) is the file path inside app without the extension
Yes but I need to do it dynamically.
resolve the id by the pathname
So in your example of the file is on app/routes/blog.posts.$id.tsx then the route ID is routes/blog.posts.$id
You need the file name to resolve it
Because /blog/posts/123 could match many different route ids
For example routes/blog/posts/$id or routes/blog.posts/$id or routes/blog.posts.123
To resolve from the pathname you would have to know the routes before, and if you know that you can do it from the route ID
Well I'm explaining my way to solution instead of the problem.
I'm trying to disable links to routes the haven't been cached yet when users are offline.
I was thinking to use caches.match to do it but figured that perhaps i need to check the _data url
how do i do it?
I can get all routes configuration from remixManifest
The remix manifest is on window.__remixManifest, there’s a routes or modules key if I’m not wrong. You can check there the list of pathnames and their route ID, then you would have to get the current pathname and check which was match
is there a way use react-router matching algorithm for that?
I’m not aware if there’s a way to use it
I know there’s a useMatch hook but I think it doesn’t work for your use case
Do you think my approach can work though?
Ah, in that case, there's a way but you'd have to copy some Remix functions that are not exported
you can check how Remix renders prefetch links https://github.com/remix-run/remix/blob/2248669ed59fd716e267ea41df5d665d4781f4a9/packages/remix-react/components.tsx#L600