Inject laravel routes into your vue application via laroute

Downloads in past


2220.2.05 years ago5 years agoMinified + gzip package size for vue-laroute in KB


npm vue2
Inject Laravel routes into your Vue application via aaronlord/laroute. I actually recommend the alternative and more slim-lined version of this package from AXN-Informatique/laravel-laroute.

Using this plugin

Adding vue-laroute to your application is as simple as any other plugin:
import Vue from 'vue';

import VueLaroute from 'vue-laroute';
import routes from '../path/to/laroute.js';

Vue.use(VueLaroute, {
  accessor: '$routes', // Optional: the global variable for accessing the router

new Vue({
  el: '#app',

You can now access your global accessor ($routes by default) in any component via this.$routes, for example:
    <h1>You can access it in your template</h1>
          <a :href="$routes.route('home')">Home</a>
          <a :href="$routes.route('products')">Home</a>
              <a :href="$routes.route('', { id: 1 })">Product 1</a>
              <a :href="$routes.route('', { id: 123 })">Product 123</a>
    <button @click.prevent="purchaseProduct(123)">Purchase product</button>

  export default {
    methods: {
      purchaseProduct (id) {
        this.$$routes.route('products.purchase', { id: id }))
          .then((response) => {
            // Handler

:scroll: Changelog

Details changes for each release are documented in the

:exclamation: Issues

Please make sure to read the Issue Reporting Checklist before opening an issue. Issues not conforming to the guidelines may be closed immediately.

:muscle: Contribution

Please make sure to read the Contributing Guide before making a pull request.

:copyright: License