Express 将(查询字符串)参数附加到当前url

Express 将(查询字符串)参数附加到当前url,express,dust.js,Express,Dust.js,表示, 假设我在http://localhost:3000/search?q=foo&sort=asc 在我的模板中,如何打印带有其他参数的链接(例如下一个分页链接): 搜寻尘埃 -- 当然,我可以: <a rel="next" href="{currentUrl}&page=2">Next results</a> 但当我在http://localhost:3000/search,因为?/&问题 谢谢你我这么做。我把它叫做{@query},这是它的签名:

表示,

假设我在
http://localhost:3000/search?q=foo&sort=asc

在我的模板中,如何打印带有其他参数的链接(例如下一个分页链接):

搜寻尘埃


--

当然,我可以:

<a rel="next" href="{currentUrl}&page=2">Next results</a>

但当我在
http://localhost:3000/search
,因为
/
&
问题

谢谢你

我这么做。我把它叫做
{@query}
,这是它的签名:

{@query string="que=ry&str=ing"/}
它将
que=ry&str=ing
与实际参数合并,因此在前面的示例中,我们使用了
http://localhost:3000/search?q=foo&sort=asc

<a rel="next" href="?{@query string="page=2"/}">Next</a>

这应该在客户端工作:。也许您可以将其调整为在快速路线或模板中工作?
<a rel="next" href="?{@query string="page=2"/}">Next</a>
<a rel="next" href="?q=foo&sort=asc&page=2">Next</a>
var dust = require('dustjs-linkedin');
var _ = require('underscore');
var qs = require('querystring');
app.use(function(req, res, next) {
  //
  // Query helper for dust
  //
  // Merge querystring parameters to the current req.query
  //
  // Suppose we are on localhost:3000/search?q=foo :
  //   - {@query string=""/} will output q=foo
  //   - {@query string="bar=baz"/} will output q=foo&bar=baz
  //   - {@query string="q=fooo&bar=baz"/} will output q=fooo&bar=baz (notice fooo takes precedence)
  //
  dust.helpers.query = function (chunk, ctx, bodies, params) {
    var str = dust.helpers.tap(params.string, chunk, ctx);

    // Parse string="" parameter
    var o = qs.parse(str);

    // Merge with req.query
    o = _.extend({}, req.query, o);

    return chunk.write(qs.stringify(o));
  }

  next();
});