ZijianHe / koa-router

Router middleware for koa.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty Url Params

toonvanstrijp opened this issue · comments

node.js version: v8.11.2

npm/yarn and version: 6.1.0

koa-router version: 7.4.0

koa version: 2.5.1

Code sample:

var Koa = require('koa');
var Router = require('koa-router');

var app = new Koa();
var router = new Router();

router.get('/avatar/email/:email', (ctx, next) => {
  ctx.status = 200;
  ctx.body = 'text'
});

app
  .use(router.routes())
  .use(router.allowedMethods());

app.listen(3000);

Expected Behavior:

When I use this url: http://localhost:3000/avatar/email/ I want the route to be catched.
It works when is use: ``http://localhost:3000/avatar/email/test@test.nl`

Actual Behavior:

When I use this url: http://localhost:3000/avatar/email/ It returns Not Found

This is how route matching works. A named param in your route :email is not optional unless it ends with a ?. See the path-to-regexp readme for more info.