Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何防止在meteor iron路由器中导航到其他页面_Meteor_Iron Router - Fatal编程技术网

如何防止在meteor iron路由器中导航到其他页面

如何防止在meteor iron路由器中导航到其他页面,meteor,iron-router,Meteor,Iron Router,我有一个表单页面,如果用户没有保存表单就离开了它,我想提醒用户。 通常,我可以通过在卸载之前声明函数window.onBeforeUnload来实现此目的 window.onBeforeUnload = function(){return 'Please save the form before navigating';} 但在我使用Meteor和Iron路由器的项目中,它似乎不起作用。 有什么建议吗?这可能是一个黑客版本,但它可以: isUnsaved = -> return un

我有一个表单页面,如果用户没有保存表单就离开了它,我想提醒用户。 通常,我可以通过在卸载之前声明函数window.onBeforeUnload来实现此目的

window.onBeforeUnload = function(){return 'Please save the form before navigating';}
但在我使用Meteor和Iron路由器的项目中,它似乎不起作用。
有什么建议吗?

这可能是一个黑客版本,但它可以:

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

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

旧帖子,但刚刚解决了它。以下是我的解决方案:

Router.route('/myPath', {
    unload: function (e, obj) {
        if(Session.get("hasChanged")){
            if (confirm("Are you sure you want to navigate away ?")) {
                // Go and do some action
            }else{
                // Redirect to itself : nothing happend
                this.redirect('/myPath');
           }
        }
    }
}

“另一个页面”=“你网站上的另一个路径”或“另一个网站上的一个页面”?你在哪里添加
window.onBeforeUnload=function(){return'请在导航之前保存表单“;}
?@PeppeL-G另一个页面仍然在我的网站上。@MurWade我在模板中添加了。[Template_name].created=function(){…here….}。当然,我有一个布尔变量来检查何时调用警报函数。@aladine这个问题可能也有帮助