如何防止在meteor iron路由器中导航到其他页面
我有一个表单页面,如果用户没有保存表单就离开了它,我想提醒用户。 通常,我可以通过在卸载之前声明函数window.onBeforeUnload来实现此目的如何防止在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 = 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这个问题可能也有帮助