diff --git a/lib/layer.js b/lib/layer.js index c7932d8..6b0477b 100644 --- a/lib/layer.js +++ b/lib/layer.js @@ -13,6 +13,7 @@ module.exports = class Layer { * @param {String=} opts.name route name * @param {String=} opts.sensitive case sensitive (default: false) * @param {String=} opts.strict require the trailing slash (default: false) + * @param {Boolean=} opts.pathIsRegexp if true, treat `path` as a regular expression * @returns {Layer} * @private */ @@ -45,6 +46,11 @@ module.exports = class Layer { if (this.opts.pathIsRegexp === true) { this.regexp = new RegExp(path); } else if (this.path) { + if (this.opts.strict === true) { + // path-to-regexp renamed strict to trailing in v8.1.0 + this.opts.trailing = false; + } + const { regexp: regex, keys } = pathToRegexp(this.path, this.opts); this.regexp = regex; this.paramNames = keys; diff --git a/lib/router.js b/lib/router.js index 9c5fadc..75e9d8f 100644 --- a/lib/router.js +++ b/lib/router.js @@ -481,8 +481,7 @@ class Router { strict: opts.strict || false, prefix: opts.prefix || '', ignoreCaptures: opts.ignoreCaptures, - pathIsRegexp: opts.pathIsRegexp, - trailing: opts.trailing + pathIsRegexp: opts.pathIsRegexp }); // if parent prefix exists, add prefix to new route diff --git a/test/lib/router.js b/test/lib/router.js index affbb14..63b454f 100644 --- a/test/lib/router.js +++ b/test/lib/router.js @@ -1657,7 +1657,7 @@ describe('Router#opts', () => { it('responds with 200', async () => { const app = new Koa(); const router = new Router({ - trailing: false + strict: true }); router.get('/info', (ctx) => { ctx.body = 'hello'; @@ -1689,7 +1689,7 @@ describe('Router#opts', () => { it('responds with 404 when has a trailing slash', async () => { const app = new Koa(); const router = new Router({ - trailing: false + strict: true }); router.get('/info', (ctx) => { ctx.body = 'hello'; @@ -1704,7 +1704,7 @@ describe('use middleware with opts', () => { it('responds with 200', async () => { const app = new Koa(); const router = new Router({ - trailing: false + strict: true }); router.get('/info', (ctx) => { ctx.body = 'hello'; @@ -1720,7 +1720,7 @@ describe('use middleware with opts', () => { it('responds with 404 when has a trailing slash', async () => { const app = new Koa(); const router = new Router({ - trailing: false + strict: true }); router.get('/info', (ctx) => { ctx.body = 'hello';