Skip to content

Commit

Permalink
Merge pull request #58 from nwoltman/docs-remove-caveat
Browse files Browse the repository at this point in the history
Remove old caveat
  • Loading branch information
delvedor committed Feb 6, 2018
2 parents b2d8136 + 562ba27 commit ba04e30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,6 @@ router.reset()
```

##### Caveats
* Since *static* routes have greater priority than *parametric* routes, when you register a static route and a dynamic route, which have part of their path equal, the static route shadows the parametric route, that becomes not accessible. For example:
```js
const assert = require('assert')
const router = require('find-my-way')({
defaultRoute: (req, res) => {
assert(req.url === '/example/shared/nested/oops')
}
})

router.on('GET', '/example/shared/nested/test', (req, res, params) => {
assert.fail('We should not be here')
})

router.on('GET', '/example/:param/nested/oops', (req, res, params) => {
assert.fail('We should not be here')
})

router.lookup({ method: 'GET', url: '/example/shared/nested/oops' }, null)
```

* It's not possible to register two routes which differs only for their parameters, because internally they would be seen as the same route. In a such case you'll get an early error during the route registration phase. An example is worth thousand words:
```js
const findMyWay = FindMyWay({
Expand Down
19 changes: 19 additions & 0 deletions test/issue-44.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ test('Parametric and static with shared prefix (nested)', t => {
findMyWay.lookup({ method: 'GET', url: '/winter/coming' }, null)
})

test('Parametric and static with shared prefix and different suffix', t => {
t.plan(1)
const findMyWay = FindMyWay({
defaultRoute: (req, res) => {
t.fail('We should not be here')
}
})

findMyWay.on('GET', '/example/shared/nested/test', (req, res, params) => {
t.fail('We should not be here')
})

findMyWay.on('GET', '/example/:param/nested/other', (req, res, params) => {
t.ok('We should be here')
})

findMyWay.lookup({ method: 'GET', url: '/example/shared/nested/other' }, null)
})

test('Parametric and static with shared prefix (with wildcard)', t => {
t.plan(1)
const findMyWay = FindMyWay({
Expand Down

0 comments on commit ba04e30

Please sign in to comment.