Aborting navigation with Meteor iron-router

前端 未结 5 1270
遥遥无期
遥遥无期 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:36

    From what I can tell this isn't possible with the iron-router API. What you could do however is override the Router.go method like so (somewhere in your client code):

    var go = Router.go; // cache the original Router.go method
    Router.go = function () {
      if(Session.get('dirty')) {
        if (confirm("Are you sure you want to navigate away?")) {
          go.apply(this, arguments);
        }
      } else {
        go.apply(this, arguments);
      }
    };
    

提交回复
热议问题