meteor - 如何防止导航到 meteor 铁路由器中的另一个页面

标签 meteor iron-router

我有一个表单页面,如果他没有保存表单就离开了,我想提醒用户。
通常我可以通过声明一个函数 window.onBeforeUnload 来达到这个目的。

window.onBeforeUnload = function(){return 'Please save the form before navigating';}

但它似乎在我使用 Meteor 和 Iron Router 的项目中不起作用。
有什么建议吗?

最佳答案

这可能是一个hacky版本,但它有效:

isUnsaved = ->
  return unless @ready()
  unless confirm 'Do you really want to leave the page?'
    Router.go(@url)

Router.onStop isUnsaved,
  only: [
    'editPost'
  ]

关于meteor - 如何防止导航到 meteor 铁路由器中的另一个页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27838055/

相关文章:

javascript - 导入很棒的:fontawesome package with Meteor and React

meteor - 具有不同端口的单个域上的多个 Heroku 应用程序

meteor - 在 Meteor 中组织我的订阅的最佳模式,而不会有发现未准备好的数据的风​​险

javascript - 对 Meteor 感到困惑 this.next() 错误 onBeforeAction

performance - 我应该在路由逻辑还是 Meteor Template Helper 中提供数据?

javascript - Meteor、Iron Router 和 Google Analytics 嵌入 API

javascript - 如何使用 DDP 从 Meteor 服务器接收流

meteor .集合 : What the different between new Collection(null) and new Collection({connection:null})

javascript - 从键值对中获取 json 值,而不需要传递 meteor 中的键

meteor - 在 Iron-Router 中为相同的 URL 推送新状态