Skip to content

Commit e2aa86c

Browse files
author
Ian Walter
committed
Adding children and parent to currentRoute
Also adding .vscode (IDE settings file) to .gitignore
1 parent c06e623 commit e2aa86c

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/*.gz
88
dist/*.map
99
explorations
1010
docs/_book
11+
.vscode

src/create-route-map.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ function addRouteRecord (
7474
path: normalizedPath,
7575
regex: compileRouteRegex(normalizedPath, pathToRegexpOptions),
7676
components: route.components || { default: route.component },
77+
children: route.children || [],
7778
instances: {},
7879
name,
7980
parent,

src/util/route.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export function createRoute (
2121
const route: Route = {
2222
name: location.name || (record && record.name),
2323
meta: (record && record.meta) || {},
24+
children: (record && record.children) || [],
25+
parent: (record && record.parent) || {},
2426
path: location.path || '/',
2527
hash: location.hash || '',
2628
query,

test/unit/specs/create-map.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ describe('Creating Route Map', function () {
6464
expect(maps.nameMap['bar.baz']).not.toBeUndefined()
6565
})
6666

67+
it('has baz route in children on bar route', () => {
68+
expect(maps.nameMap.bar.children[0].name).toEqual('bar.baz')
69+
})
70+
6771
it('in development, has logged a warning concerning named route of parent and default subroute', function () {
6872
process.env.NODE_ENV = 'development'
6973
maps = createRouteMap(routes)

test/unit/specs/create-matcher.spec.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { createMatcher } from '../../../src/create-matcher'
33

44
const routes = [
55
{ path: '/', name: 'home', component: { name: 'home' }},
6-
{ path: '/foo', name: 'foo', component: { name: 'foo' }},
6+
{
7+
path: '/foo',
8+
name: 'foo',
9+
component: { name: 'foo' },
10+
children: [
11+
{ path: '', name: 'foo.baz', component: { name: 'Baz' } }
12+
]
13+
}
714
]
815

916
describe('Creating Matcher', function () {
@@ -32,4 +39,14 @@ describe('Creating Matcher', function () {
3239
match({ name: 'foo' }, routes[0])
3340
expect(console.warn).not.toHaveBeenCalled()
3441
})
42+
43+
it('should return the matched route with children populated', () => {
44+
const route = match({ name: 'foo' })
45+
expect(route.children[0].name).toEqual('foo.baz')
46+
})
47+
48+
it('should return the matched route with parent populated', () => {
49+
const route = match({ name: 'foo.baz' })
50+
expect(route.parent.name).toEqual('foo')
51+
})
3552
})

0 commit comments

Comments
 (0)