Skip to content

Commit

Permalink
fix: strip trailing /index
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Apr 26, 2019
1 parent c5b73be commit eb07b7e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ function groupRoutes(
).map(sorted => sorted.route)
}
}
return new Set(sortRoutes([...routes]).map(sorted => sorted.route))
return new Set(sortRoutes([...routes]).map(({ route }) => ({
...route,
path: route.path.replace(/\/index$/, '')
})))
}

export function toRoutes(
Expand Down
5 changes: 5 additions & 0 deletions test/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ Array [
"name": "index-vue",
"path": "/",
},
Object {
"file": "user/index.vue",
"name": "user-index-vue",
"path": "/user",
},
Object {
"file": "about.vue",
"name": "about-vue",
Expand Down
2 changes: 1 addition & 1 deletion test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toRoutes } from '../src'

test('simple', () => {
expect(toRoutes(['index.vue', 'about.vue'])).toMatchSnapshot()
expect(toRoutes(['index.vue', 'about.vue', 'user/index.vue'])).toMatchSnapshot()
})

test('directory', () => {
Expand Down

0 comments on commit eb07b7e

Please sign in to comment.