vue-tidyroutes plugin
VueJS routes definitions that can be created anywhere in your project.
Under the hood
It's just a singleton object that store all your routes for future export to the vue-router.
Install
npm install --save vue-tidyroutes
Example
app.js
;;; Vue const router = routes: VueTidyRoutes router el: '#app' template: ` <div> <h1>Example</h1> <router-view></router-view> </div> `
component1.js
; const Component1 = template: '<div><h2>Component1</h2></div>' ; VueTidyRoutes; ;
Usage
VueTidyRoutes.route(path, options)
VueTidyRoutes.route(path)
VueTidyRoutes.route(path).child(path, options)
Create a route:
VueTidyRoutes.route(path, options)
const Foo = template: '<div>foo</div>' const Bar = template: '<div>bar</div>' let route1 = VueTidyRoutes let route2 = VueTidyRoutes
Nested routes:
There are two ways to define nested routes
const Foo = template: '<div>foo<router-view></router-view></div>' const Bar = template: '<div>bar</div>' VueTidyRoutes VueTidyRoutes
const Foo = template: '<div>foo<router-view></router-view></div>' const Bar = template: '<div>bar</div>' VueTidyRoutes
Detailed example at /example
To run the example just: npm run example
Methods
Method | Description | Example |
---|---|---|
.route | Defines a new route with the given options | VueTidyRoutes.route('/home', {...options}) |
.children | Defines a group of child for the current route | VueTidyRoutes.route('/contact').children({ '/phone': ...options}, {'/location': ...options}) |
.child | Defines a single child for the route | VueTidyRoutes.route('/places).child('/centralpark', { ...options }) |
.export | Returns all the defined routes in the entire project in the format that VueRouter expects | const router = new VueRouter({routes: VueTidyRoutes.export()}) |
License
The MIT License (MIT). Please see License File for more information.