Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adi518/vue-flatten-routes
https://github.com/adi518/vue-flatten-routes
Last synced: 8 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/adi518/vue-flatten-routes
- Owner: adi518
- Created: 2018-04-01T20:07:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-11-20T15:35:41.000Z (about 6 years ago)
- Last Synced: 2024-11-28T09:39:37.326Z (25 days ago)
- Language: JavaScript
- Size: 119 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vue-Flatten-Routes
Get a flat routes array from your [`vue-router`](https://github.com/vuejs/vue-router) compatible routes.
## Install
```
npm install --save vue-flatten-routes
```
## Usage
```js
import { flattenRoutes } from 'vue-flatten-routes'const routes = [
{
name: 'foo',
path: 'foo',
children: [
{
name: 'foo-first-level-child',
path: 'foo-first-level-child',
children: [
{
path: 'foo-second-level-child',
name: 'foo-second-level-child',
children: [
{
path: 'foo-third-level-child',
name: 'foo-third-level-child'
}
]
}
]
},
{
name: 'foo-first-level-child-2',
path: 'foo-first-level-child-2'
}
]
},
{
path: 'bar',
children: [
{
name: 'bar-first-level-child',
path: 'bar-first-level-child',
children: [
{
name: 'bar-second-level-child',
path: 'bar-second-level-child'
}
]
}
]
}
]console.log(JSON.stringify(flattenRoutes(routes), null, 2))
/* Output:
[
{
"name": "foo",
"path": "foo",
"level": 0,
"root": true,
"nested": false,
"hasNamedParent": false
},
{
"name": "foo-first-level-child",
"path": "foo-first-level-child",
"level": 1,
"root": false,
"nested": true,
"hasNamedParent": true
},
{
"name": "foo-second-level-child",
"path": "foo-second-level-child",
"level": 2,
"root": false,
"nested": true,
"hasNamedParent": true
},
{
"name": "foo-third-level-child",
"path": "foo-third-level-child",
"level": 3,
"root": false,
"nested": true,
"hasNamedParent": true
},
{
"name": "foo-2nd-first-level-child-2",
"path": "foo-first-level-child-2",
"level": 1,
"root": false,
"nested": true,
"hasNamedParent": true
},
{
"path": "bar",
"level": 0,
"root": true,
"nested": false,
"hasNamedParent": false
},
{
"name": "bar-first-level-child",
"path": "bar-first-level-child",
"level": 1,
"root": false,
"nested": true,
"hasNamedParent": false
},
{
"name": "bar-second-level-child",
"path": "bar-second-level-child",
"level": 2,
"root": false,
"nested": true,
"hasNamedParent": true
}
]
*/
```