Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested routers with router prefix responds with the status code 404 #155

Closed
roshangade opened this issue Jul 29, 2015 · 3 comments
Closed

Comments

@roshangade
Copy link

I tried to explore the nested routers by adding the router prefix in it, but it responds with the status code 404.

Here is working example without adding the router prefix:

var forums = new Router();
var posts = new Router();

posts.get('/', function *(next) {...});
posts.get('/:pid', function *(next) {...});
forums.use('/forums/:fid/posts', posts.routes());
app.use(forums.routes());

And here is the nested routers with the router prefix, which is not working:

var forums = new Router({
    'prefix': '/forums'
});
var posts = new Router({
    'prefix': '/:fid/posts'
});

posts.get('/', function *() {
    this.body = 'posts'
});
posts.get('/:pid', function *() {
    this.body = 'post'
});

forums.use(posts.routes()); // OR forums.use('/', posts.routes());

app.use(forums.routes());

Could you please suggest or help me here. Thanks in advance.

@neVERberleRfellerER
Copy link

Try this:
forums.use('', posts.routes());
It is strange, but AFAIK it is only way.

@roshangade
Copy link
Author

Thanks!

@kudos
Copy link

kudos commented Aug 22, 2015

I just encountered this too, it's a bug imo.

ruiquelhas pushed a commit to seegno-forks/koa-router that referenced this issue Oct 16, 2015
- Fixes ZijianHe#161, fixes ZijianHe#155, fixes ZijianHe#156.
- Removes dependency on koa-compose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants