Routing does not handle optional route parameter with prefix
See original GitHub issuenode.js version:
13.3.0
npm/yarn and version:
npm 6.4.1
yarn 1.19.2
(this is what i’m using)
@koa/router
version:
8.0.5
koa
version:
2.11.0
Code sample:
const router = require('@koa/router')()
const Koa = require('koa')
// following line included to demonstrate difference in underlying library - version 6.1.0
const { pathToRegexp } = require("path-to-regexp")
const app = module.exports = new Koa()
const middleware = async (ctx, next) => { ctx.body = 'it worked'; return await next() }
const withoutIDRoute = '/foo{.:ext}?'
router.get('withoutID', withoutIDRoute, middleware)
app.use(router.routes()).use(router.allowedMethods())
console.log(pathToRegexp(withoutIDRoute).test('/foo.json')) // outputs true
console.log(pathToRegexp(withoutIDRoute).test('/foo')) // outputs true
app.listen(3080)
Expected Behavior:
http://localhost:3080/foo.json
returnsit worked
as a text responsehttp://localhost:3080/foo
returnsit worked
as a text response- More generally,
@koa/router
matches routes thatpath-to-regexp
matches (as documented in this section)
Actual Behavior:
Both of the aforementioned URLs result in a 404 Not Found response
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:17 (15 by maintainers)
Top Results From Across the Web
React Router with optional path parameter - Stack Overflow
My question is, can we declare it in one route? If I add only the second row then the route without the parameter...
Read more >How to pass an optional parameter to a route? - Laracasts
I am not sure why the router does not deal with the query-parameter. I feel that it should be. The router should scan...
Read more >Optional parameters in Web API Attribute Routing
In this article, I am going to discuss Optional Parameters in Web API Attribute Routing with some examples. You can make a URI...
Read more >Routing - Laravel - The PHP Framework For Web Artisans
Basic Routing. Redirect Routes; View Routes; The Route List · Route Parameters. Required Parameters; Optional Parameters · Named Routes · Route Groups. Middleware ......
Read more >Routing in Razor Pages
The framework has no way of knowing which page to call. You can disambiguate between routes by adding route parameters and/or constraints to ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@niftylettuce ☝🏽
@smarts one moment, I’m going to have @3imed-jaberi look at that.