Coder Social home page Coder Social logo

vue-breadcrumbs's Introduction

vue-breadcrumbs

npm npm GitHub stars

Vue breadcrumbs builds on the official vue-router package to provide simple breadcrumbs. This package is backwards compatible to support both Vue 1.x and Vue 2.x.

DEMO

Installation

<script src="../dist/vue-breadcrumbs.min.js"></script>
Vue.use(VueBreadcrumbs)

or via npm:

$ npm install vue-breadcrumbs
import VueBreadcrumbs from 'vue-breadcrumbs'

Vue.use(VueBreadcrumbs)

Define the matching breadcrumb text in your routes.

An options object can also be passed into the plugin to specify your own template and rendering methods if desired. For example:

Vue.use(VueBreadcrumbs, {
  template: '<nav class="breadcrumb" v-if="$breadcrumbs.length"> ' +
    '<router-link class="breadcrumb-item" v-for="(crumb, key) in $breadcrumbs" :to="linkProp(crumb)" :key="key">{{ crumb | crumbText }}</router-link> ' +
    '</nav>'
});

By default the plugin will autoregister a breadcrumbs component which is globally accessible in your app (thanks to HermannBjorgvin. To disable this functionality you can set the registerComponent option to false when registering the component, like so:

Vue.use(VueBreadcrumbs, {
  registerComponent: false
});

Note: if referencing directly in the browser rather than as a module, there is no way to stop the default component from registering.

Usage

Vue 1.x

Use the breadcrumb: property of a route or subRoute, e.g.:

router.map({
  '/': {
    component: Page,
    breadcrumb: 'Home Page',
    subRoutes: {
      '/foo': {
        component: Foo,
        breadcrumb: 'Foo Page'
      },
      '/bar': {
        component: Bar,
        breadcrumb: 'Bar Page'
      }
    }
  }
})

Vue 2.x

Use the meta.breadcrumb: property of a route or child route, e.g.:

new VueRouter({
  routes: [
    {
      path: '/', 
      component: Page,
      meta: {
        breadcrumb: 'Home Page',
      },
      children: [
        {
          path: '/foo', 
          component: Foo,
          meta: {
            breadcrumb: 'Foo Page'  
          }
        },
        {
          path: '/bar', 
          component: Bar,
          meta: {
            breadcrumb: 'Bar Page'
          }
        }
      ]
    }
  ]
})

You can then render the breadcrumbs using the included <breadcrumbs> component or using your own markup logic with the global this.$breadcrumbs property which will return an array of active matched routes.

License

MIT

vue-breadcrumbs's People

Contributors

casperlaitw avatar hermannbjorgvin avatar limonte avatar samturrell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-breadcrumbs's Issues

Not render on the screen

Hello! I need help, I can not make it work

Vue2 , Vue-cli-3

main.js

import VueBreadcrumbs from 'vue-breadcrumbs'
Vue.use(VueBreadcrumbs)

DashboardNavBar.vue

...
<div><breadcrumbs></breadcrumbs></div>

Simply do not play anything on the screen and alert on the console

console

[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.

Any idea? Grate.

The content of children component is not updated

I installed the package and setup like below. The problem is when I visit children components, the breadcrumbs was showed up right, but the content of that child component didn't get change. For example, when I entered the cart page it didn't show up the content of CartPage component and still keeps content from HomePage component.

router/routes.js

export default [
    {
        name: 'home',
        path: '/',
        component: HomePage,
        meta: {
            breadcrumb: 'Homepage',
        },
        children: [
            {
                name: 'product',
                path: '/products/:id/:slug',
                component: ProductSingle,
                meta: {
                    breadcrumb: 'Product',
                },
            },
            {
                name: 'cart',
                path: '/cart',
                component: CartPage,
                meta: {
                    breadcrumb: 'Cart',
                },
            },
        ]
    }
];

router/index.js

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';
import VueBreadcrumbs from 'vue-breadcrumbs';

Vue.use(VueRouter);
Vue.use(VueBreadcrumbs);

const router = createRouter();

export default router;

/**
 * The router factory
 */
function createRouter() {
    const router = new VueRouter({
        mode: 'history',
        routes,
        scrollBehavior(to, from, savedPosition) {
            return {x: 0, y: 0}
        }
    });

    return router;
}

vue-breadcrumbs component opened wrong page

Hello,
In my Laravel 5.8 / vuejs 2.6 app I need to use breadcrumbs and I installed
vue-breadcrumbs pligin

and from its example description I see that I must to adjust all routes in resources/js/routes.js which
I want to use in breadcrumbs, so I wrote :

import Home from './components/BS4/Home.vue';
import ForumsList from './components/BS4/forum/ForumsList.vue';
...
export const routes = [

    // FRONTEND PAGES BLOCK START

    {
        path: '/',
        component: Home,
        meta: {
            breadcrumb: 'Home Page',
            requiresAuth: false
        },
        name: 'HomePage',

        children: [
            {
                path: '/forums-list',
                component: ForumsList,
                meta: {
                    breadcrumb: 'Forums',
                    requiresAuth: false
                },
                name: 'ForumsList',
                children: [
                    {
                        path: '/forum/:slug',
                        component: ForumView,
                        meta: {
                            breadcrumb: 'Forum View',
                            requiresAuth: false
                        },
                        name: 'ForumView',
                        children: [
                            {
                                path: '/forum-thread/:slug',
                                component: ForumThreadView,
                                meta: {
                                    breadcrumb: 'Forum Thread',
                                    requiresAuth: false
                                },
                                name: 'ForumThreadView'
                            },

                        ]
                    },
                ]
            },

        ],


    },

    // FRONTEND PAGES BLOCK END


// BACKEND CRUD PAGES BLOCK START
    {
        path: '/admin/dashboard',
        component: DashboardContainer,
        meta: {
            requiresAuth: true,
            authGroupsAccess: ['Admin', 'Manager'],
        },
        name: 'DashboardIndex'
    },

But it does not work as I expect:
clicking on "/forums-list" link with browser url changed I see content in breadcrumbs is changed to “Home Page"/"Forums”
but in browser home page is opened. Has my routes systax error?

Not working in Vue2

Hi,

I does not work with vue2. It always says: Matched routes (0):

// update: Just say the pull request...

Any idea?

How to inject routes parameter ?

Hello everybody !
I'm looking for a way to include parameters, because for every root with params, I always get the path defined in the route file (without the injection).
For example, when I'm on my article page, and then I click on the relative part of the breadcrumb I get a link to 'articles/:id', but 'articles/1' was excepted.

I don't know if I'm really clear, but if someone know how to do that, it should be really cool ! :)

Thk !

Problem with / url

Hello,
I've just installed this component and found myself with an issue. I'm using routes like this (Copilot style):

export default new Router({
    mode: 'history',
    linkActiveClass: 'is-active',
    routes: [
        {path: '/login', component: Login, meta: {auth: false}},
        {
            path: '/',
            component: DefaultLayout,
            meta: {breadcrumb: 'Inicio'},
            children: [
                {path: 'dashboard', name: 'dashboard', component: Dashboard, meta: {auth: true, breadcrumb: 'Dashboard'}},             
            ]
        },
    ]
})

And in result, my breadcrumb shows
Inicio > Dashboard
But both urls point to /dashboard.
If I have 3 breadcrumb levels, 2nd and 3rd are ok, but 1st points to 3rd.
1st > 2nd > 3rd
1st will point to 3rd path. very weird.

Thanks for your time

Custom with Element UI?

I bas on Element UI, could example to custom:

<el-breadcrumb separator="/">
  <el-breadcrumb-item :to="{ path: '/' }">homepage</el-breadcrumb-item>
  <el-breadcrumb-item>promotion management</el-breadcrumb-item>
  <el-breadcrumb-item>promotion list</el-breadcrumb-item>
  <el-breadcrumb-item>promotion detail</el-breadcrumb-item>
</el-breadcrumb>

I got error Failed to mount component: template or render

Hello,
In my Laravel 5.8/vuejs 2.6 app I installed https://github.com/samturrell/vue-breadcrumbs components.
I added definitions to resources/js/routes.js, but I got error :

app.js?dt=1569060337:129470 [Vue warn]: Failed to mount component: template or render function not defined.

found in

---> <VueBreadcrumbs>
       <AppHeader> at resources/js/components/BS4/AppHeader.vue
         <Root>

When I tried to use this component in my header component resources/js/components/BS4/AppHeader.vue:

<template>
	<div class="app_header_container">


				<vue-breadcrumbs></vue-breadcrumbs>

	</div>

	
</template>

<script>
    import {bus} from '../../app';
    import appMixin from '../../appMixin';

    import Vue from 'vue';

    import VueBreadcrumbs from 'vue-breadcrumbs';
//    Vue.use(VueBreadcrumbs)

    Vue.use(VueBreadcrumbs, {
        template: '<nav class="breadcrumb" v-if="$breadcrumbs.length"> ' +
            '<router-link class="breadcrumb-item" v-for="(crumb, key) in $breadcrumbs" :to="linkProp(crumb)" :key="key">{{ crumb | crumbText }}</router-link> ' +
            '</nav>'
    });
    
    export default {

        components: {
            VueBreadcrumbs // Register your component
        },

        data: function () {
            ...

Are there some parameter which must be set in definition of
<vue-breadcrumbs
?

Nested routes with params links

Nested routes with params links are rendered as the path pattern and not with the route params.

trying to debug it, will also upload an example soon.

Nuxt ssr without "runtimeCompiler"

I do not want to include in my assembly "runtimeCompiler".
Please add support for ssr without "runtimeCompiler"

[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.

image

Every crumb in breadcrumb href pointing last route triggered.

In breadcrumbs, all the crumbs href is last visited route.
<nav class="breadcrumb"> ' + '<a href="#/Page1" class="breadcrumb-item router-link-exact-active router-link-active"> Home </a><a href="#/Page1" class="breadcrumb-item router-link-exact-active router-link-active"> Page1 </a> ' + '</nav>

Update breadcrumb value from component

Is it possible to update breadcrumb value from the component? For example when I go to article page, I want to show the title of the article in breadcrumb, not something general like "Article page".

localization breadcrumbs

is it possible to localization breadcrumbs ?
for example, my website has three languages (Eng, Fr, Span)
How to translate breadcrumbs?

Thanks.

How do I use dynamic subroutes with this component?

I need to use something like this:

export default new Router({ mode: 'history', routes: [ { path: '/', name: 'Home', component: Home }, { path: '/informativos', name: 'Informativos', component: Informativos, meta: { breadcrumb: 'Informativos' }, children: [ { path: '/informativo/:id/:title', component: InformativoDetalhes, meta: { breadcrumb: 'Título' } } ] } ] })

Build breadcrumbs without nested routes (subRoutes)

I would like to create a breadcrumb trail without having to use nested routes. It seems that it's not possible.

My application has these pages:

  • Homepage
  • Product overview
  • Add product

The pages don't need any of the nested component structure that VueRouter offers, because they will be rendered in the top-level <router-view> outlet.

However, I would like to have a breadcrumb which shows a path that will help the users to navigate back to the previous page, e.g.:
Homepage > Product overview > Add product

I managed to get this kind of breadcrumb when using nested routes (subRoutes) in this example:
https://jsfiddle.net/adriaanmeuris/9aur04nv/

However, I'm not able to build such a breadcrumb without making use of nested routes.

Any idea how I can define a breadcrumb path myself (i.e. without using subRoutes)?

linkProp issues

Hi,

I just tried this plugin but got this error by using the example :
Property or method "linkProp" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property
&

"Error in render: "TypeError: _vm.linkProp is not a function"

I'm not really sure what I'm doing wrong, any one could help me?

Thanks!

Breadcrumb doesn't works with I pass params via vue-router

When I have an usual route like:

/issue

Without ID
Every thing is OK! But when I have passing properties, something happen.

/issue/:id

With ID
And the links on breadcrumbs be localhost:8080/#/issue/:id but doesn't make sense. Should be only localhost:8080/#/issue. Help me

Don't work (Meteor + Element UI)

I base on Meteor + Element UI.
get error

printer.js:170 [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. 
(found in <Breadcrumbs>)

computed value

How I can get computed value from router

      {
        path: ':id',
        name: 'request-view',
        props: true,
        component: () => import('@pages/processing/requests/RequestEdit'),
        meta: {
          breadcrumb: ':id', // I need to get computed id
        }
      },

:id contains user id, and I want put it to my breadcrumb.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.