Skip to content
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

Merged
merged 6 commits into from
Jul 2, 2020

Conversation

yyx990803
Copy link
Member

  • Refactored <router-view> implementation
  • Upgrading to vue@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 pass props, so the user no longer needs to bind it. This simplifies <router-view> slot usage with <transition>/<keep-alive> to:

      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <keep-alive>
            <component :is="Component"></component>
          </keep-alive>
        </transition>
      </router-view>

      RFC needs to be updated accordingly.

    • also added a warning when detecting old usage (<router-view> directly inside <transition>/<keep-alive>)

return (
// pass the vnode to the slot as a prop.
// h and <component :is="..."> both accept vnodes
(slots.default && slots.default({ Component: component })) || component
Copy link
Member Author

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.

Copy link
Member

@posva posva left a 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 🚀

return (
// pass the vnode to the slot as a prop.
// h and <component :is="..."> both accept vnodes
(slots.default && slots.default({ Component: component })) || component
Copy link
Member

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:

Suggested change
(slots.default && slots.default({ Component: component })) || component
slots.default ? slots.default({ Component: component }) : component

Copy link
Member

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

Copy link
Member Author

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.

@posva posva merged commit 994c073 into master Jul 2, 2020
@posva posva deleted the router-view-refactor branch July 2, 2020 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants