Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
samturrell committed Nov 10, 2017
1 parent 6bf480f commit a8f34c9
Showing 1 changed file with 57 additions and 3 deletions.
60 changes: 57 additions & 3 deletions README.md
@@ -1,11 +1,65 @@
# vue-laroute



[![npm](https://img.shields.io/npm/v/vue-laroute.svg)](https://www.npmjs.com/package/vue-laroute)
[![vue2](https://img.shields.io/badge/vue-2.x-brightgreen.svg)](https://vuejs.org/)

Inject laravel routes into your vue application via laroute
Inject Laravel routes into your Vue application via [aaronlord/laroute](https://github.com/aaronlord/laroute). I actually recommend the alternative and more slim-lined version of this package from [AXN-Informatique/laravel-laroute](https://github.com/AXN-Informatique/laravel-laroute).

## Using this plugin

Adding vue-laroute to your application is as simple as any other plugin:

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

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

You can now access your global accessor (`$routes` by default) in any component via `this.$routes`, for example:

```js
<template>
<div>
<h1>You can access it in your template</h1>
<nav>
<ul>
<li>
<a :href="$routes.route('home')">Home</a>
</li>
<li>
<a :href="$routes.route('products')">Home</a>
<ul>
<li>
<a :href="$routes.route('products.show', { id: 1 })">Product 1</a>
</li>
<li>
<a :href="$routes.route('products.show', { id: 123 })">Product 123</a>
</li>
</ul>
</li>
</ul>
</nav>
<button @click.prevent="purchaseProduct(123)">Purchase product</button>
</div>
</template>

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



Expand Down

0 comments on commit a8f34c9

Please sign in to comment.