-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle undefined path in router resolve #1904
Conversation
✅ Deploy Preview for vue-router canceled.
|
It’s preferred not to provide the path property altogether. What use case would this help with? |
Yes, but it should not matter whether path is provided as I found this bug when fixing the code recently migrated from Vue 2 to Vue 3. Thus, behavior in question is not backwards compatible. Also there is no readable error thrown. If the intention is really to require passing non-null path property or not passing it at all, it should be clearly stated in some exception being thrown. However, I doubt that's a good option, since adding some smart-defaults is easy, better compliant with TS spec and compatible with previous version of |
Yes, TS does allow it but doesn’t allow to check for it with obj.property 🙃 |
Piece of code looks like this:
Basically, it redirects if path or query has been specified.
This would look quite cumbersome. What I did to fix this issue, is I wrote an util function to get rid of undefined object props and used it like this:
Still, looks like a hack.. |
And because most of the times in JS code I believe, that making this distinction for the sake of it does not make a lot of sense. Also, please take a look at this piece of code, which does exactly the same, what I did by introducing this change: router/packages/router/src/matcher/index.ts Line 251 in b480bd1
|
Sorry, I couldn't push some changes to the PR, I don't know why as the checkbox seems to be checked so I created #1909. Feel free to make a review or even to create a new PR from there! This could break some types for some people so I want to check a bit more before |
Suppose we execute for example:
Error would be thrown during
route.resolve
as we only check iflocation
has propertypath
but not if the path is defined and non null.