Why does router not pass parameters 404?

  node.js, question

A route is registered

router.get('/user/:id', user.find);

What I want to design is to pass in the id one operation and not pass in the id parameter another operation.
However, if you do not pass the id parameter, it will be 404. I can only register another one.

router.get('/user/', user.find);

I feel this usage is very strange.

The koa-router module is used.

The parameter you write like this is calledpath variable, which is a required part of routing, should be used if you want to be an optional parameter.query parameter(i.e.:?(Introduction)

Amendment:

I haven’t seen this before.koa-router, I am in accordance with the standardhttpThe access logic suggested it, but after reading the document, I found that this thing is not a normal abnormal condition (almost Jabberwocky), so my above suggestion cannot be used.

Here’s how it works:

router.get('/user/:id?'  , user.find);

Then when the client accesses, it can not fill inid, directly/user/This access, see the document:

图片描述

Never usedkoa, don’t know what kind of logic this is, I refuse to obey

Add:

Regarding routing specifications, in the:

图片描述

By another librarypath-to-regexpTo deal with