Aborting navigation with Meteor iron-router

前端 未结 5 1218
遥遥无期
遥遥无期 2021-01-12 08:54

I have a (client-side) router in a Meteor app, and links using the {{pathFor}} helper.

I am setting a dirty flag in the Session

5条回答
  •  天涯浪人
    2021-01-12 09:22

    The new behavior for iron router should make this easier because it requires a call to this.next() in the onBeforeAction hook (see iron router guide), so only call that when the session is not dirty or the user confirms the warning:

    if(Session.get('dirty')) {
        if(confirm("Are you sure you want to navigate away?")) {
            this.next();
        }
    } else {
        this.next();
    }
    

提交回复
热议问题