-
GoalProvide an easy way to determine if a request is shallow in the router events API BackgroundMy team and I has implement a page loader on one of our sites, and it works, but we want to disable the loader on shallow requests. I searched around for a bit and stumbled upon #3322, which is the same issue as the one we're having. ProposalSee pull request #13243 for proposed implementation. I believe the easiest way to implement this is to add whether or not the route is shallow to the event callbacks. There are a couple of ways this could be implemented. Here's one example of how it can be done, and how I've implemented it in my PR. Example 1:By converting the callback parameter Using the callback function with this solution would look something like this: router.events.on('routeChangeStart', (request) => {}); // request = { as: 'example.com', shallow: true } Example 2:This is the way I've implemented it in my PR. The main reason why I've done this is for backwards compatibility. Using the callback function with this solution would look something like this: router.events.on('routeChangeStart', (as, shallow) => {}); // as = 'example.com', shallow = true The only alternative way to solve this that I can think of is to do routing "manually" (without the next router) or create some kind of wrapper for it, which, in my opinion, would be overly complicated for such an easy solution. I have not written an RFC before, so feedback on how I could improve it for next time is greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
I think we should expect an object instead of boolean as second parameter. In that case other config or properties can be added (if required) in future without increasing the length of the parameters.
|
Beta Was this translation helpful? Give feedback.
-
I'm using "routeChangeComplete" for marketing pageview events and I want to exclude shallow requests. This feature would be awesome. |
Beta Was this translation helpful? Give feedback.
-
For anyone that might be waiting: I have created another PR (#19802) for this issue 😸 |
Beta Was this translation helpful? Give feedback.
-
Good news everyone! The PR got merged, so we're getting this feature 🎉 |
Beta Was this translation helpful? Give feedback.
Good news everyone! The PR got merged, so we're getting this feature 🎉