Breadcrumbs plugin for Vue.js 2 framework that allows to select parent route in route meta object with no need of sub-routing

Overview

vue-2-crumbs

Breadcrumbs plugin for Vue.js 2 framework allows to select parent route in route meta object with no need of sub-routing.

Features:

Installation

$ npm install vue-2-crumbs --save
import Vue from 'vue'
import Vue2Crumbs from 'vue-2-crumbs'

Vue.use(Vue2Crumbs)

After that <app-breadcrumbs></app-breadcrumbs> component would be at your disposal.

Usage

Use the breadcrumb property in route's meta to provide route label or/and parent route name as in example below:

Simple Example

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home', // Be sure to set 'name' property for the route you want to be "parent" route
      component: Home,
      meta: {
        breadcrumb: 'Home Custom Label' // This is a shorthand for case you want to set just breadcrumb label
      }
    },
    {
      path: '/about',
      name: 'about',
      component: About,
      meta: {
        breadcrumb: {
          label: 'Custom About page Label',
          parent: 'home' // Here you should use exact string as for name property in "parent" route
        }
      }
    },
    {
      path: '/contact',
      name: 'contact', // name property would also used as default route label for breadcrumbs
      component: Contact,
      meta: {
        breadcrumb: {
          parent: 'about'
        }
      }
    }
  ]
})
Result:

Simple Usage Result

Custom template

(new in v0.5.1)

By default component's template is ul > li > router-link. But starts with v0.5.1 you can provide custom template using scoped slots and container prop at app-breadcrumbs component.

You will have label string to object and utils object at your disposal. utils is helper object, that serves you to contain all information you may want to use in custom template. Aware that utils can be undefined, so you need to check it before use it in template.

To define utils object just add it to breadcrumb object in router definition or directly in component.

For targeting current page in breadcrumb chain, use named slot - current. Parents breadcrumb chunks is default slot. Note: Obviously, you should define router-link at some point, in your custom template for make breadcrumbs work.

Example:

<app-breadcrumbs container="nav">
  <h6 slot-scope="{to, label, utils}">
    <router-link
      :to="to"
      class="your-custom-class"
      exact
      :itemprop="utils && utils.itemprop"
    >{{label}}</router-link>
    <i class="fas fa-angle-right"></i>
  </h6>

  <span
    slot="current"
    slot-scope="{label}"
    class="custom-current-class"
  >{{label}}</span>
</app-breadcrumbs>

Sub-routing

Plugin also supports default behavior for nested routes:

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Page,
      children: [
        {
          path: '/about',
          component: About,
          meta: {
            breadcrumb: {
              label: 'Custom About page Label'
            }
          },
          children: [
            {
              path: '/contact',
              component: Contact,
              meta: {
                breadcrumb: 'Contact Custom Label'
              }
            }
          ]
        }
      ]
    }
  ]
})

You can combine this approaches:

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      children: [
        {
          path: 'about',
          component: About,
          meta: {
            breadcrumb: {
              label: 'Custom About page Label'
            }
          },
          children: [
            {
              path: 'contact',
              name: 'contact',
              component: Contact,
              meta: {
                breadcrumb: 'Contact Custom Label'
              }
            },
            {
              path: 'terms',
              component: Terms,
              meta: {
                breadcrumb: {
                  label: 'Terms',
                  parent: 'contact'
                }
              }
            }
          ]
        }
      ]
    }
  ]
})
Result:

Combine Usage Result

Define Breadcrumb Data in Component

You easily can define breadcrumbs information in page components. This would overwrite data in the router. For example: Terms.vue

breadcrumb: {
  label: 'Terms Label From Component',
  parent: 'contact'
},
data () {
  return {
    ...
  }
}

Contact.vue

breadcrumb: 'Contact Label from Component',
data () {
  return {
    ...
  }
}

Router

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      children: [
        {
          path: 'about',
          component: About,
          meta: {
            breadcrumb: {
              label: 'Custom About page Label'
            }
          },
          children: [
            {
              path: 'contact',
              name: 'contact',
              component: Contact,
              meta: {
                breadcrumb: {
                  parent: 'home'
                }
              }
            },
            {
              path: 'terms',
              component: Terms
            }
          ]
        }
      ]
    }
  ]
})
Result:

Combine Usage Result

Define parent's params, query, hash

(new in v0.5.1)

You can provide not only route's name as a parent property, but also it's params, query and hash. Just use object with corresponding keys:

parent: {
  name: 'category',
  params: {
    catSlug: 'latest',
  },
  query: {
    sort: 'ASC'
  },
  hash: '#test'
}

Dynamic Breadcrumbs

You can use dynamic data to provide breadcrumb information (as label and parent) in page component. IMPORTANT! Because of the tech limitations, you need to be sure, that dynamic breadcrumb is the last one in the list. Plugin doesn't allowed to build breadcrumbs list with dynamic part in the middle of it. To handle this cases, please check using parentsList property.

Terms.vue

breadcrumb () {
  return {
    label: this.title,
    parent: this.parent
  }
},
data () {
  return {
    title: 'Dynamic Terms Label',
    parent: 'home'
  }
}

Router

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      children: [
        {
          path: 'about',
          component: About,
          meta: {
            breadcrumb: {
              label: 'Custom About page Label'
            }
          },
          children: [
            {
              path: 'contact',
              name: 'contact',
              component: Contact,
              meta: {
                breadcrumb: {
                  parent: 'home'
                }
              }
            },
            {
              path: 'terms',
              component: Terms
            }
          ]
        }
      ]
    }
  ]
})
Result:

Combine Usage Result

Using parentsList

If you need to use dynamic breadcrumb in the middle of your breadcrumb list, than you should provide whole chain in component's parentsList property. You need to provide list of objects that contain path and label, like in example below:

Post.vue

breadcrumb () {
  return {
    label: this.postTitle,
    parentsList: [
      {
        to: {
          name: 'category',
          params: {
            catSlug: this.$route.params.catSlug
          }
        },
        label: this.categoryTitle
      },
      {
        to: {
          name: 'blog',
          query: {
            section: 'news'
          },
          hash: '#hot'
        },
        label: 'Blog Page'
      },
      {
        to: '/',
        label: 'Home'
      }
    ]
  }
},
data () {
  return {
    postTitle: '',
    categoryTitle: ''
  }
},
created () {
  let {categorySlug, postSlug} = this.$route.params
  // Some API calls
  // ...
  this.postTitle = 'Breaking News!'
  this.categoryTitle = 'Latest'
}

Router

new VueRouter({
  routes: [
    {
      path: '/',
      name: 'home',
      component: Home
    },
    {
      path: '/:categorySlug',
      name: 'category',
      component: Category
    },
    {
      path: '/:categorySlug/:postSlug',
      component: Post
    }
  ]
})
Result:

Combine Usage Result

License

MIT

Comments
  • refactor: clean code

    refactor: clean code

    fix lint errors, fix bug, refactor code for easy reading fix issue #11

    • need check breadcrumb in component and params issue.

    • can use function in router for label

    • parentList is unused with recursive parent call exemple:

    {
                path: 'offres-emploi/:id-:slug-:location',
                component: (/* webpackChunkName: "OffreEmploiV" */) => import('./views/OffreEmploiView.vue'),
                children: [
                  {
                    path: '',
                    name: 'offre-emploi',
                    component: (/* webpackChunkName: "OffreEmploi" */) => import('./views/OffreEmploi.vue'),
                    meta: {
                      breadcrumb: {
                        parent: 'offres-emploi',
                        label: function () { return this.$store.state.offre.job_title }
                      }
                    }
                  },
    '''
    opened by darkiron 8
  • add dynamic label in parent

    add dynamic label in parent

    Hi, How I cant add a Dynamic Label ? I try with :

     breadcrumb () {
        return {
          label: 'Postuler',
          parent:  {
            name: 'offre-emploi',
            params: {
              id: this.$route.params.id,
              slug: this.$route.params.slug,
              location: this.$route.params.location
            },
            label: this.$store.state.offre.job_title
          }
        }
      },
    

    label don't set with job_title.

    opened by darkiron 4
  • How to set `params or query` of parent breadcrumb?

    How to set `params or query` of parent breadcrumb?

    The first thanks for This. Some time I would like to use params/query of parent breadcrumb

    {
          path: '/contact',
          name: 'contact', // name property would also used as default route label for breadcrumbs
          component: Contact,
          meta: {
            breadcrumb: {
              parent: 'about',
              params:[id, name, ....],
              query: [......]
            }
          }
        }
    
    opened by thearabbit 3
  • Cannot read property 'components' of undefined

    Cannot read property 'components' of undefined

    vue.esm.js:1741 TypeError: Cannot read property 'components' of undefined at a.getBreadcrumb (index.js:268) at a.getDirectParentRoute (index.js:335) at a.getParentRoute (index.js:361) at a.getAncestorsRoutesArray (index.js:378) at a.parentRoutes (index.js:259) at wa.get (vue.esm.js:3142) at wa.evaluate (vue.esm.js:3249) at a.parentRoutes (vue.esm.js:3507) at a.eval (eval at no (vue.esm.js:10680), :3:91)

    opened by RiadhRahmi 2
  • Local import

    Local import

    Hi, is there a way to locally import the plugin instead of globally?

    I tried to import it in my wrapper component but always getting 'Failed to mount component: template or render function not defined.'

    <template>
      <app-breadcrumbs></app-breadcrumbs>
    </template>
    
    <script>
    import Vue2Crumbs from 'vue-2-crumbs';
    
    export default {
      name: 'MyBreadcrumb',
      components: { 'app-breadcrumbs': Vue2Crumbs },
    };
    </script>
    
    
    opened by szhang-ezypay 1
  • /src/index.js missing in git

    /src/index.js missing in git

    Hey, I fail to build this from source. It seems like /src/index.js is missing.

    Apparently the .gitignore entry

    index.js
    

    also causes /src/index.js to not be included into git, and thus making building impossible.

    To hide only the build output

    /index.js
    

    should only exclude the build output.

    opened by luckydonald 1
  • update vue-router dependency?

    update vue-router dependency?

    Great plugin,

    error "vue-2-crumbs#vue-router@^2.1.x" doesn't satisfy found match of "[email protected]"

    Is there any reason vue-router 3 isnt allowed?

    opened by bjensen 1
  • is this active?

    is this active?

    Hi, when i'm trying to use the component it's not showing anything and return this < !--function (a, b, c, d) { return createElement(vm, a, b, c, d, true); }-- >

    opened by Sweeeeep 0
  • Ошибка Cannot read property 'components' of undefined

    Ошибка Cannot read property 'components' of undefined

    Добрый день!

    Заинтересовала данная библиотека. Попытался прикрутить к своему проекту, но выводится ошибка та, что в заголовке

    Пример роутса ` const routes = [ { path: '/', component: home, name: 'home', meta: { breadcrumb: { label: 'Home' } } }, { path: '/basket_tool', component: basket_tool, name: 'basket_tool', meta: { breadcrumb: { label: 'Basket tool', parent: 'home', } } }, ];

    const router = new VueRouter({ mode: 'history', routes: routes });

    new Vue({ el: '#main_application', router: router, }); `

    Ошибка вываливается в строке var matchedComponent = matchedRouteRecord.components.default;

    Попытался подебажить, обнаружил что в функцию getBreadcrumb: function getBreadcrumb(route) {

    Приходят все написанные мною роутсы (с названием, с путями, всё как положено), но самым первым приходит роут со свойствами path и fullpath равными "/" и с пустым свойством route.matched

    Никак не могу понять откуда берется этот самый пустой роут

    opened by KazarminDmitriy 0
  • Dynamic passing the params

    Dynamic passing the params

    Hello Everyone I am trying to use vue-2-crumbs and I have some routes as follows in my router.js file this route is considered as the parent { path: "/metaService/:id/child", name: "IndexMetaServiceChild", meta: { title: "IndexMetaServiceChild", requiresAuth: true, permission: "platform.meta_service.get_child", breadcrumb: { label: "IndexMetaServiceChild", parent: "MetaServices", }, }, component: () => import("@/views/metaService/IndexMetaServiceChild"), },

    and this route is considered as its following child

    { path: "/metaServices/metaServicesChild/edit/:parent/:id", name: "EditMetaServiceChild", meta: { title: "EditMetaServiceChild", requiresAuth: true, permission: "platform.meta_service.show", breadcrumb: { label: "EditMetaServiceChild", parent: { name: "IndexMetaServiceChild", params: { id: ":parent",

          }
        },
      },
    },
    

    the bug is that I want to pass the ":parent" params to its parent dynamically however the ":id" param is passed by default. Is there any solution? Thank you

    opened by sara-farokhi 0
  • Doesn't work with SSR

    Doesn't work with SSR

    I'm getting the error:

    [Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

    This originates in the AppBreadcrumbs component. Pages without crumbs are working fine.

    It appears the problem lies with the template parameter, replacing it with a render function would fix the issue.

    opened by dahousecat 0
  • Fix for parentDynamicRoutes being cleared on route change

    Fix for parentDynamicRoutes being cleared on route change

    Closes: #5

    Here's a link to a reproduction: https://codesandbox.io/s/vue-template-yy32j (When you click on 'foo' in the navigation, the router will only show the id, while it should show the full breadcrumb with parents list).

    opened by adamwardecki 2
  • Change template

    Change template

    Currently we have template

    <ul class="breadcrumbs-container" :is="container" v-if="$router">
                                        <template v-if="parentRoutes.length">
                                            <template v-for="route in parentRoutes">
                                                <slot :to="route.to" :label="route.label" :utils="route.utils">
                                                    <li class="parent-breadcrumb">
                                                        <router-link
                                                                :to="route.to"
                                                                exact>
                                                            {{route.label}}
                                                        </router-link>
                                                    </li>
                                                </slot>
                                            </template>
                                        </template>
                                        <li v-if="!isInitialEmptyRoute" class="current-breadcrumb">
                                            <slot name="current" :label="getRouteLabel(currentRoute)">
                                                <a>
                                                    {{getRouteLabel(currentRoute)}}
                                                </a>
                                            </slot>
                                        </li>
                                    </ul>
    

    But unfortunately, we cant change latest li. I would offer change it to

    
                                        
                                            <slot v-if="!isInitialEmptyRoute" name="current" :label="getRouteLabel(currentRoute)">
                                               <li  class="current-breadcrumb">
                                                <a>
                                                    {{getRouteLabel(currentRoute)}}
                                                </a>
                                               </li>
                                            </slot>
    

    Via slot we can change li, add class and so on

    opened by websitevirtuoso 0
Owner
Kirill
Kirill
Vue breadcrumbs

breadcrumbs Vue breadcrumbs builds on the official vue-router package to provide simple breadcrumbs. Demo Support Support SSR Setting parent route wit

Ivan Demidov 96 Dec 14, 2022
Routing and navigation for your Vue SPA. Vue 单页应用导航管理器

vue-page-stack English | 简体中文 A Vue SPA navigation manager,cache the UI in the SPA like a native application, rather than destroy it. Example preview

hezf 583 Jan 9, 2023
Vue.js plugin for PhotoEditor SDK

vue-pesdk PhotoEditor SDK Vue.js wrapper ?? Note PhotoEditor SDK is a product of img.ly GmbH. In order to use PhotoEditor SDK inside one of your produ

img.ly 26 Apr 14, 2022
Access Control List plugin for VueJS 2.0

vue-acl: access control list in vuejs We will help you to control the permission of access in your app for yours components and routes Installation #

Leonardo Vilarinho 382 Dec 30, 2022
vue navigation manager

vue-nav The library is a navigation manager, it is similar to native mobile app. require vue 2.x and vue-router 2.x. 中文文档 Function support cache last

nearspears 63 Sep 12, 2022
Simple page-by-page navigation for Vue.js based on your html templates with ssr support

Simple page-by-page navigation for Vue.js based on your html templates with ssr support

Denis 2 Jun 3, 2021
Vue bottom navigation

vue-bottom-navigation Table of Contents Demo Installation Usage Constructor Options License Demo Demo Installation # npm $ npm install bottom-navigat

imanmalekian31 63 Jan 8, 2023
Breadcrumbs plugin for Vue.js 2 framework that allows to select parent route in route meta object with no need of sub-routing

Breadcrumbs plugin for Vue.js 2 framework that allows to select parent route in route meta object with no need of sub-routing.

Newway 0 Apr 20, 2018
👷A component that allows creating forms with two-way binding from data object with default HTML fields and custom, like multi-block or AJAX-select.

From Builder A component that allows creating forms with two-way binding from data object with default HTML fields and custom, like multi-block or AJA

Awes.io 66 Dec 22, 2022
Dynamic select box for vuejs - allows configuration of remote / local object fields to be collected

VueFieldSelect vue-field-select Side note - similar / related projects vue-autocompletion vue-field-select (this) Installation via NPM First Install v

Vahid Hedayati 0 Dec 12, 2019
Vue.js plugin that allows you to reference methods on parent classes

vue-super Provides a $super handler for accessing parent vue methods from a subclass. Behaves similarly to python's super implementation. vue-super is

Ryan P Kilby 34 Dec 1, 2022
A storybook decorator that allows you to use routing-aware components in your stories

storybook-router A Storybook decorator that allows you to use your routing-aware components. You can simply use the library link component within your

Gianni Valdambrini 257 Oct 18, 2022
Breadcrumbs for Vue.js

vue-breadcrumbs Vue breadcrumbs builds on the official vue-router package to provide simple breadcrumbs. This package is backwards compatible to suppo

Sam Turrell 149 Nov 25, 2022
Vue breadcrumbs

breadcrumbs Vue breadcrumbs builds on the official vue-router package to provide simple breadcrumbs. Demo Support Support SSR Setting parent route wit

Ivan Demidov 96 Dec 14, 2022
Real Estate Pub-Sub - Real Estate PubSub Model With Vue

Real Estate PubSub Model Introduction In the Real Estate Pub/Sub System, when a

null 0 Jan 8, 2022
A sub module of EdgeGallery MECM which responsible for the orchestration portal.

mecm-fe Introduction repo for mecm fe Architecture See Configuration Reference. Installation npm install Instructions Project setup npm install Compil

EdgeGallery 21 Sep 27, 2022
Javascript canvas drawing tool using Redis pub/sub

Javascript canvas drawing tool using Redis pub/sub Features Uses FastAPI for serving WebSockets Draw commands are communicated using Redis PubSub Ther

Hannu Ylitalo 3 Jun 16, 2022
Stylable searchable select component for VueJS. This component is renderless so you are free to customize it how you need to!

Please note that this package is still under active development. We encourage everyone to try it and give feedback. ss-select Searchable stylable sele

Miras Mustimov 27 Dec 27, 2022
Vue2 component, that allows you to drag object wherever you want

vue-drag-it-dude Vue2 component, that allows you to drag object wherever you want What this can do Drag and drop DOM elements inside parent (or docume

Max Novikov 74 Nov 24, 2022
Laqu-l 130 Dec 27, 2022