8000 Warn about root paths without a leading slash (fix #2550) by Sayegh7 · Pull Request #2591 · vuejs/vue-router · GitHub
[go: up one dir, main page]

Skip to content

Warn about root paths without a leading slash (fix #2550) #2591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix(create-route-map): show prettier warning message
  • Loading branch information
Sayegh7 committed Aug 29, 2019
commit f8d35b45cd494815c0fdae0c32f52e8326edfd19
7 changes: 2 additions & 5 deletions src/create-route-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,10 @@ export function createRouteMap (
const found = pathList
// check for missing leading slash
.filter(path => path && path.charAt(0) !== '*' && path.charAt(0) !== '/')
// split the path to get the root path part only
.map(path => path.split('/')[0])
// remove duplicates caused by split child paths
.filter((path, index, pathList) => pathList.indexOf(path) === index)

if (found.length > 0) {
warn(false, `Non-nested routes must include a leading slash character. Fix the following routes: ${found.join('\n')}.`)
const pathNames = found.map(path => `- ${path}`).join('\n')
warn(false, `Non-nested routes must include a leading slash character. Fix the following routes: \n${pathNames}`)
}
}

Expand Down
7 changes: 2 additions & 5 deletions test/unit/specs/create-map.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('Creating Route Map', function () {
{ path: 'bar', name: 'bar', component: Bar }
])
expect(console.warn).toHaveBeenCalledTimes(1)
expect(console.warn.calls.argsFor(0)[0]).toEqual('[vue-router] Non-nested routes must include a leading slash character. Fix the following routes: bar.')
expect(console.warn.calls.argsFor(0)[0]).toEqual('[vue-router] Non-nested routes must include a leading slash character. Fix the following routes: \n- bar')
})

it('in development, it does not log the missing leading slash when routes are valid', function () {
Expand All @@ -117,10 +117,7 @@ describe('Creating Route Map', function () {
it('in production, it does not log the missing leading slash warning', function () {
process.env.NODE_ENV = 'production'
maps = createRouteMap([
{ path: '/', name: 'home', component: Home },
{ path: 'bar', name: 'bar', component: Bar },
{ path: 'foo', name: 'foo', component: Foo },
{ path: '*', name: 'any', component: Baz }
{ path: 'bar', name: 'bar', component: Bar }
])
expect(console.warn).not.toHaveBeenCalled()
})
Expand Down
0