#Hey folks! I’ve built a little hook that might...
1 messages · Page 1 of 1 (latest)
Fantastic work!
This will be incredibly useful to myself and many others.
Thank you!
Glad you liked it! 😄 and thanks for the ⭐️!
dont mind me asking but
can you explain me what that hook does exactly
No problem at all All it does is make a preflight request to a serverless route that you can specify depending on the current route of your application. I found it to be pretty useful in an application I’m building where the user journey is pretty clear. e.g. you have to go through a discovery page before going to an articles page, in this case we can preflight and wake up several serverless functions that are used by the articles page when the user is on the discovery page.
In a sense, you’re waking up a few serverless functions before getting to the page that needs it. Sure, it might shut down after awhile if the user is still browsing the current page but at least it solves for when the user just wants to navigate past a specific page
No problem!
@fallen haven fantastic work! but since it uses next/router, the package currently only works in the pages directory. Can you make it work in the app router too, considering it is now already stable?
(for reference, in the app router the pathname can be retrieved with usePathname from next/navigation)
Hey @strange oriole apologies for the late reply! Had work in the day 🙂 Oh sure thing, let me look into that! I wonder if usePathname can be used for the old folder structure as well (i.e. pages/)
Done! Added this in the latest release https://github.com/lws803/next-use-warmroutes/releases/tag/v0.1.1 v0.1.1
iirc it doesn't work for the pages directory; the two directories use different routers, so do check if it works for the old router
Seems like it does, in a way 🤔 usePathname returns the actual path instead of the path with placeholder, if you use something like /[id].tsx.
So I had to change up the matcher a little and use blob matching instead which will allow you to specify matches like these: {"/*": "/test"}where any immediate subpath of / will be matched
I think it works for the pages directory, at least the version that was published yesterday, i tested it today