Permalink
Browse files

fix(): '/:id' is not supposed to be matched by route

* test(): test bug where a :key param is appended to an existing route

* fix(): fix bug where '/:id' is not supposed to be matched by route

When navigating to `/` when `/` and `/:id` is defined it still tries to match
`/:id` while id will be undefined, causing null to be the route matched.
  • Loading branch information...
TylorS authored and staltz committed Apr 18, 2016
1 parent 18d963a commit cd7a363628b3a544be6d709ea4256a2e0d23e90b
Showing with 11 additions and 1 deletion.
  1. +1 −1 src/index.js
  2. +10 −0 test/index.js
View
@@ -82,7 +82,7 @@ function switchPath(sourcePath, routes) {
matchedValue = routes[pattern]
}
const params = matchesWithParams(sourcePath, pattern)
const params = matchesWithParams(sourcePath, pattern).filter(Boolean)
if (params.length > 0 && betterMatch(sourcePath, matchedPath)) {
matchedPath = extractPartial(sourcePath, pattern)
View
@@ -213,4 +213,14 @@ describe('switchPath corner cases', () => {
expect(path).to.be.equal('/home/123/456')
expect(value).to.be.equal('123:456')
})
it('should not match a :key type route if no params are given', () => {
const {path, value} = switchPath('/', {
'/': 'root',
'/:id': (id) => `$id`
})
expect(path).to.be.equal('/')
expect(value).to.be.equal('root')
})
});

0 comments on commit cd7a363

Please sign in to comment.