Reputation: 317
I'm currently trying to implement a flowrouter trigger function that stops the current route and prompts you for a pin.
Once the pin is provided, this is checked and if correct; the user will continue to their requested route.
I've included my Flow router route, enter trigger function and the pin prompt function below:
The stop event on the router works fine. The pin capture function also works no problem. Grabbing the requested path on success also works however when this is pushed into FlowRouter.go(); the URL changes however the app doesn't follow the route.
// 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);
}
}
If anyone knows why this isn't working, please let me know! Thanks
Upvotes: 0
Views: 42
Reputation: 21846
My code looks similar. Instead of find the path using FlowRouter.current, I use context.path. Instead of using stop(), I use redirect(). Here is my code.
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);
}
}
Upvotes: 1