Skip to content

Adding name mode section in passing props to route component #2499

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

Closed
wants to merge 1 commit into from

Conversation

suprabhasupi
Copy link

Fixes (#2493)

@suprabhasupi
Copy link
Author

@posva Is there any issue with this PR. Why its is not getting merged? Please let me if there are changes to be done.

@posva
Copy link
Member

posva commented Nov 29, 2018

No, no problems. It's not getting merged yet because I haven't checked :)

Copy link

@autumnwoodberry autumnwoodberry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This behavior is not really one of the "modes" and the example in the documentation has a comment/example that explains it already:

// for routes with named views, you have to define the `props` option for each named view:
{
  path: '/user/:id',
  components: { default: User, sidebar: Sidebar },
  props: { default: true, sidebar: false }
}

Perhaps we could remove this comment/example from the code at the top of the page and move it to a new section at the bottom titled "Usage with named views". This way it would be explained as an explicit feature which would be harder to miss. You could even mention that the rules still apply for using the different modes. Maybe something like this:

## Usage with named views

A route with [named views](named-views.html) must have an explicitly defined `props` option for each named view.

In the following example, the `header` and `default` views will recieve the `id` prop, but the `footer` view will not.

```js
const router = new VueRouter({
  routes: [
    {
      path: '/user/:id',
      components: {
        header: Header,
        default: User,
        footer: Footer
      },
      props: {
        header: true,
        default: true,
      }
    }
  ]
});
```

The `props` option for each named view can still be defined using any of the available modes:

```js
const router = new VueRouter({
  routes: [
    {
      path: '/user/:id',
      components: {
        header: Header,
        default: User,
        footer: Footer
      },
      props: {
        header: { sticky: true },
        default: route => route.query,
        footer: true,
      }
    }
  ]
})
```

routes: [
{
path: '/user-profile',
component: {location: Location, userInfo: UserInfo},

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be components instead of component?

@posva
Copy link
Member

posva commented Jun 24, 2020

I think having this documented at https://router.vuejs.org/guide/essentials/passing-props.html as it currently is makes more sense

@posva posva closed this Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants