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

Add query parameters argument to Router.prototype.url method #227

Closed
nschloe opened this issue Jan 12, 2016 · 8 comments
Closed

Add query parameters argument to Router.prototype.url method #227

nschloe opened this issue Jan 12, 2016 · 8 comments

Comments

@nschloe
Copy link

nschloe commented Jan 12, 2016

koa-router's url method supports name and parameters. In addition to this, I would like to construct a URL with query parameters, e.g.,

/test?q=abc&number=123

Is it possible to use the url method for it yet? Proper escaping would be nice too.

@mastilver
Copy link

It's already available using https://github.com/koajs/koa

Check out: https://github.com/koajs/koa/blob/9f80296fc49fa0c03db939e866215f3721fcbbc6/test/request/query.js#L23

router.get('/test', function *(next) {
    var ctx = this;

    console.log(ctx.query.q);
    // => 'abc'
    console.log(ctx.query.number);
    // => 123
});

@nschloe
Copy link
Author

nschloe commented Jan 19, 2016

Thanks for the reply! Do you think the same would be possible for the url method? Right now, I'm using it in the context of

this.status = 303;
this.redirect(router.url('document', doc.document) + '?revision=' + doc._id);

The latter ?revision=... part is the one that been bugging me.

@mastilver
Copy link

It's not handled

What do you think about:

router.url('document', doc.document, {
    query: {
        revision: doc._id
    }
})

I will try to send a PR tonight

@nschloe
Copy link
Author

nschloe commented Jan 19, 2016

Just what I was looking for.

@wachunei
Copy link
Contributor

Hi. Are there any plans on supporting this?

@jbielick jbielick changed the title query parameters in urls Add query parameters argument to Router.prototype.url method Oct 22, 2017
@jbielick
Copy link
Collaborator

@wachunei No plans that I've seen, but a PR could be opened with some work that matches what was discussed here—seems like there would be support for it.

@wachunei
Copy link
Contributor

PR sent, check #396

@jbielick
Copy link
Collaborator

published at 7.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants