Javascript 流星';s Iron路由器-路由前更改路径
在根据某些逻辑(例如Javascript 流星';s Iron路由器-路由前更改路径,javascript,url,meteor,path,iron-router,Javascript,Url,Meteor,Path,Iron Router,在根据某些逻辑(例如会话变量)路由页面之前,是否有方法更改路径?例如: // Before routing Router.onBeforeAction(function () { if(Session.get('key') === true) { prependToPath('prefix'); } }); 您可以使用Iron.Location.get().path获取当前路径,运行您的逻辑,然后在Router.go()中使用新路径。像这样: // If abc
会话
变量)路由页面之前,是否有方法更改路径?例如:
// Before routing
Router.onBeforeAction(function () {
if(Session.get('key') === true) {
prependToPath('prefix');
}
});
您可以使用
Iron.Location.get().path
获取当前路径,运行您的逻辑,然后在Router.go()
中使用新路径。像这样:
// If abc is set on the URL, then keep it there
if (Session.get('abc') === true) { // You can use better logic here
Router.go('/abc' + Iron.Location.get().path);
}
并确保您在某个地方将Session.set('abc')=false,否则它将继续循环,在无限循环中添加/abc