-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(matcher): avoid empty records to be reached
Resolves posva/unplugin-vue-router#81
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just dropping by, as this commit has broke a lot of routes on my site - specifically it broke ability to provide external URL redirects in routes:
I found this to be a much simpler way to handle external linking, rather than creating a custom router-link. Any chance to fix this regression? I would imagine I am not the only one doing this. Otherwise the workaround is to provide a random component, like so:
756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, thanks for sharing! That kind of route record is nonvalid: it will report an error in TS, and that's why it didn't prevent this change from happening.
Other solutions such as global navigation guards and a simple switch case inside to handle a redirection table or even the one you mentioned about a custom router link are the expected ways of doing things rather than a
beforeEnter()
guard. I recommend you migrate to one of those instead.756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this is relevant, but this update broke this use case where I'm using "empty" routes to structure a hierarchy of metadata. Example:
In the component I use it to dynamically generate a side menu using
router.getRoutes()
and parsing the metadata. With this update the method doesn't return the "empty" routes, breaking this use case.756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's relevant. Either add a
name
or acomponent
to make it considered as a regular route and appear inrouter.getRoutes()
756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not 100% sure if my use case is related to this. I used the following structure to get the top level navigation highlighted when a sub-menu item is active using the linkActiveClass: 'active',
Since the update the linkActiveClass doesn't bubble up anymore.
756f755
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not that it doesn't bubble up anymore, the route record is now (correctly) hidden from route list as it shouldn't be reachable. This avoids reaching that page via a link (e.g.
/products
) by accident and finding yourself with a half empty page (missing the nested content). If the page can be reached, adding a name will make it reachable and should fix your issue. In most cases, the desired behavior is adding a child route with an empty path{ path: '', component: ... }
, you can even name that route and make your router link point to it