【问题标题】:How to create a route with multiple parameters?如何创建具有多个参数的路由?
【发布时间】:2016-11-25 12:12:18
【问题描述】:

我正在使用一个名为 quickWallet 的支付系统,它在我的应用程序上重定向到以下 URL:

http://localhost:3000/payment-response?status=failed&id=1009891&billnumbers=1480072195&checksum=2fcdb781a18f795459b3f388135419eeae02dda12da05e2613eae8ce4f16e514

如何使用 FlowRouter 处理它?

这是我当前的路线定义:

FlowRouter.route('/payment-response?',{

    name:'payment Response Received',
    action(){ 
        BlazeLayout.render('paymentResponse');

    }
});

我在控制台中得到关注:

kadira_flow-router.js?hash=9cd2691…:519 路径没有路由:/payment-response?status=failed&id=1009891&billnumbers=1480072195&checksum=2fcdb781a18f795459b3f388135419eeae02ddace12405e21413e>

我做错了什么?

【问题讨论】:

    标签: javascript meteor flow-router


    【解决方案1】:

    不使用问号定义路径,因为它只是表示 URL 查询部分的标记。

    正如 FlowRouter 的 first example 所示:

    FlowRouter.route('/blog/:postId', {
        action: function(params, queryParams) {
            console.log("Yeah! We are on the post:", params.postId);
        }
    });
    

    查询参数可用作action() 方法的第二个参数。

    因此,代码应该是这样的:

    FlowRouter.route('/payment-response',{
        name: 'paymentResponseReceived',
        action(_params, queryParams){
            // render your layout with the queryParams
        }
    });
    

    【讨论】:

    • 感谢好友为我工作。我可以通过 queryParams.status 或 queryParams.id 访问各个参数。
    猜你喜欢
    • 2013-12-27
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 2016-10-12
    • 2014-02-04
    • 2012-07-09
    • 2020-12-24
    • 1970-01-01
    相关资源
    最近更新 更多