【问题标题】:Adding a password prompt when accessing specified FlowRouter routes访问指定 FlowRouter 路由时添加密码提示
【发布时间】:2016-06-09 11:45:42
【问题描述】:

我目前正在尝试实现一个 flowrouter 触发功能,该功能会停止当前路由并提示您输入引脚。

一旦提供了密码,就会检查它是否正确;用户将继续他们请求的路线。

下面我已经包含了我的Flow路由路由、进入触发功能和pin提示功能:

路由器上的停止事件工作正常。 引脚捕获功能也没有问题。 然而,当它被推送到 FlowRouter.go(); 时,成功获取请求的路径也可以。 URL 发生了变化,但应用程序不遵循该路线。

// Flow Router route

StaffRoutes.route('/browse', {
    name: "browseAccounts",
    triggersEnter: [enterPin],
    action: function() {
        BlazeLayout.render('cardLayout', {
            main: "browseSearch"
        })
    }
});



// Enter PIN code trigger function

function enterPin(context, redirect, stop) {
    // saving the requested route for after pin login success
    let route = FlowRouter.current();
    Session.set('redirectAfterPin', route.path);

    // this just shows a hidden pin pad
    showPinPrompt();

    // stopping the current route
    stop();
}

// pinPromptSubmission
function pinSubmission() {
    // presume pin is correct
    if (pinIsCorrect) {

        // grab requested path and initiate FlowRouter go
        let newPath = Session.get('redirectAfterPin');
        FlowRouter.go(newPath);
    }
}

如果有人知道为什么这不起作用,请告诉我!谢谢

【问题讨论】:

  • 看起来不错。什么不工作?在 pin 输入后显示 pin 提示或重定向。
  • 输入 pin 后,URL 路径会更改,但 DOM 不会更改并保留在当前模板上。 (抱歉回复晚了,我正在休假!)

标签: javascript meteor meteor-blaze flow-router


【解决方案1】:

我的代码看起来很相似。我没有使用 FlowRouter.current 查找路径,而是使用 context.path。我没有使用stop(),而是使用redirect()。这是我的代码。

FlowRouter.route("/loans/apply", {
  name: "loanApplication",
  action(params) {
    renderLayoutWith(<LoanApplicationContainer />, "Apply Loan");
  },
  triggersEnter: [redirectAnonymous]
});

function redirectAnonymous(context, redirect) {
  if(!Meteor.userId()) {
    redirect('/login?redirectUrl=' + context.path);
  }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    • 2017-04-10
    • 1970-01-01
    相关资源
    最近更新 更多