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

Named Views with vue-router possible? #150

Open
jawa-the-hutt opened this issue Jan 19, 2022 · 1 comment
Open

Named Views with vue-router possible? #150

jawa-the-hutt opened this issue Jan 19, 2022 · 1 comment
Labels
enhancement New feature or request pr welcome

Comments

@jawa-the-hutt
Copy link

Is there a way to achieve what's shown here in the Vue Router docs where you essentially end up with a route config that has something like this:

{
  path: '/settings',
  // You could also have named views at the top
  component: UserSettings,
  children: [{
    path: 'emails',
    component: UserEmailsSubscriptions
  }, {
    path: 'profile',
    components: {
      default: UserProfile,
      helper: UserProfilePreview
    }
  }]
}

I'm most interested in the page being loaded into the named view as I have a Tab component in a parent route that I'd like to use to change what's contained in the router-view via the tab header. Right now, all that happens as far as I can tell is that the page is going into the default router-view.

@hannoeru hannoeru added enhancement New feature or request pr welcome labels Jan 20, 2022
@ranseur92
Copy link

ranseur92 commented Sep 28, 2022

There is a way to achieve this, but it's not "pretty".

Register both components globally, and you can pass a components object to the route block.

<route>
{
  components: {
    sidebar: { template: '<accounts-filter />' },
    default: { template: '<accounts />' }
  },
  meta: {
    layout: 'sidebar'
  }
}
</route>

My sidebar layout:

<template>
  <div class="container mx-auto px-4 pt-4 dark:text-light text-dark">
    <Header />
    <div class="flex">
      <RouterView name="sidebar" />
      <RouterView />
    </div>
  </div>
</template>

<script lang="ts" setup>
import Header from "@/components/Header.vue";
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
Development

No branches or pull requests

3 participants