Skip to content

Commit dfabe51

Browse files
authored
docs(b-nav): add example markup for using vue-router/nuxt-child (closes #3999) (#4000)
1 parent 464d257 commit dfabe51

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/components/nav/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,64 @@ The `card-header` prop is only needed when you are applying `tabs` or `pills` st
316316

317317
The `card-header` prop has no effect if the `<b-nav>` is `vertical`.
318318

319+
### Using with Vue Router
320+
321+
Have your card `<b-nav>` control vue router nested routes via `<router-view>` or `<nuxt-child>`
322+
components, to created tabbed content that changes with route URL:
323+
324+
```html
325+
// On page with route `/some/route`
326+
<div>
327+
<b-card title="Card Title" body-class="text-center">
328+
<template v-slot:header>
329+
<b-nav card-header tabs>
330+
<!-- <b-nav-item>'s with child routes. Note the trailing slash on the first <b-nav-item> -->
331+
<b-nav-item to="/some/route/" exact exact-active-class="active">Active</b-nav-item>
332+
<b-nav-item to="/some/route/foo" exact exact-active-class="active">Foo</b-nav-item>
333+
<b-nav-item to="/some/route/bar" exact exact-active-class="active">Bar</b-nav-item>
334+
</b-nav>
335+
</template>
336+
337+
<!-- Child route gets rendered in <router-view> or <nuxt-child> -->
338+
<router-view></router-view>
339+
<!-- Or if using Nuxt.js
340+
<nuxt-child></nuxt-child>
341+
-->
342+
</b-card>
343+
</div>
344+
```
345+
346+
Note: Vue Router does not support defining active routes with hashes (`#`), which is why you must
347+
define the "tab" content as child routes.
348+
349+
**Example router config for above:**
350+
351+
<!-- eslint-disable no-unused-vars, no-undef -->
352+
353+
```js
354+
const routes = [
355+
{
356+
path: '/some/route',
357+
component: SomeRouteComponent,
358+
// Child route "tabs"
359+
children: [
360+
{ path: '', component: DefaultTabComponent },
361+
{ path: 'foo', component: FooTabComponent },
362+
{ path: 'bar', component: BarTabComponent }
363+
]
364+
}
365+
]
366+
```
367+
368+
One can also use Vue Router
369+
[named routes](https://router.vuejs.org/guide/essentials/named-routes.html#named-routes) and/or
370+
route params instead of path based routes.
371+
372+
For more details see:
373+
374+
- [Vue Router `<router-view>`](https://router.vuejs.org/api/#router-view)
375+
- [Nuxt.JS `<nuxt-child>`](https://nuxtjs.org/api/components-nuxt-child)
376+
319377
## Accessibility
320378

321379
If you're using `<b-nav>` to provide a navigation bar, be sure to add a `role="navigation"` to the

0 commit comments

Comments
 (0)