Skip to content

Commit

Permalink
fix(route-alis): preserve route previous aliases (#91)
Browse files Browse the repository at this point in the history
* fix: add route alias to array instead of overwriting it

* fix: eslint errors

* fix: module test because alias is now an array
  • Loading branch information
j1gs4w authored and farnabaz committed Dec 6, 2019
1 parent 5d43019 commit 91f3c80
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ function processRoutes () {
for (const route of routes) {
route.meta = route.meta || {}
route.alias = route.alias || []
if (typeof route.alias === 'string') {
route.alias = [route.alias]
}

if (route.path === '/amp' || route.path.indexOf('/amp/') === 0) {
route.meta.amp = true
} else {
route.alias = '/amp' + route.path
route.alias.push('/amp' + route.path)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion test/module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('Generates routes', () => {

test('Routes should be correctly localized', () => {
routes.forEach((route) => {
expect(route.alias).toEqual(`/amp${route.path}`)
expect(route.alias).toEqual([`/amp${route.path}`])
})
})
})
Expand Down

0 comments on commit 91f3c80

Please # to comment.