-
-
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
refactor: refactor router-view + fix keep-alive route guard this context #344
Conversation
src/RouterView.ts
Outdated
return ( | ||
// pass the vnode to the slot as a prop. | ||
// h and <component :is="..."> both accept vnodes | ||
(slots.default && slots.default({ Component: component })) || component |
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.
Note here we are passing component
, which is a vnode, to the slot as Component
. Changes in vue@3.0.0-beta.18
allows <component :is="">
and h
to accept an existing vnode which makes it possible.
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.
This is great! It's so much easier than what I was doing in the branch feat/keep-alive 😭
I'm going to add a few tests and this should bring us very close to beta 🚀
src/RouterView.ts
Outdated
return ( | ||
// pass the vnode to the slot as a prop. | ||
// h and <component :is="..."> both accept vnodes | ||
(slots.default && slots.default({ Component: component })) || component |
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 think here we could just use a ternary:
(slots.default && slots.default({ Component: component })) || component | |
slots.default ? slots.default({ Component: component }) : component |
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.
Aah, I didn't see the parentheses correctly. But I think it would make more sense to use the slot if there is one without falling back to component
. This way the user could hide it if they wanted to
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.
Yeah I just followed the original logic. We should probably use a ternary indeed.
<router-view>
implementationvue@3.0.0-beta.18
fixes navigation guard
this
when route component is inside<keep-alive>
passing component vnode via
<router-view>
slot gets rid of the need to passprops
, so the user no longer needs to bind it. This simplifies<router-view>
slot usage with<transition>/<keep-alive>
to:RFC needs to be updated accordingly.
also added a warning when detecting old usage (
<router-view>
directly inside<transition>/<keep-alive>
)