#Hey folks! I’ve built a little hook that might...

1 messages · Page 1 of 1 (latest)

mortal parrotBOT
#

Thread automatically created, you can use it to discuss about the project!

drifting kite
#

Fantastic work!

#

This will be incredibly useful to myself and many others.

#

Thank you!

fallen haven
#

Glad you liked it! 😄 and thanks for the ⭐️!

hidden shuttle
#

can you explain me what that hook does exactly

fallen haven
# hidden shuttle 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

hidden shuttle
#

thats interesting

#

thanks

fallen haven
#

No problem!

strange oriole
#

@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)

fallen haven
#

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/)

fallen haven
strange oriole
fallen haven
#

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

drifting kite
#

I think it works for the pages directory, at least the version that was published yesterday, i tested it today