我有一个运行在knockout.js应用程序中的sammy.js。我目前正在尝试重定向缺少尾部斜杠的路由(例如/#/stop/1/100032
)。我想将所有缺少尾部斜杠的页面重定向到带有斜杠的页面。如何从没有尾部斜线的页面重定向到尾部斜线的页面
使事情变得复杂,我还想在没有这样的路线的情况下有一个错误页面。
function RoutesViewModel() {
var self = this;
self.router = Sammy(function() {
this.get('/#/stop/:agency_id/:stop_id/', function() {
app.page.state('bus');
app.stop.setCurrentById(this.params['agency_id'], this.params['stop_id']);
mixpanel.track('stop page load', {
'route': '/#/stop/' + this.params['agency_id'] + '/' + this.params['stop_id'] + '/',
});
});
this.get('/(.*[^\/])', function() {
this.redirect('/',this.params['splat'],'/');
});
});
self.router.error = function (message, error) {
app.page.header("Unable to find your page");
app.page.message("The page you've requested could not be found.<br /><a href=\"/\">Click here</a> to return to the main page.");
}
self.run = function() {
self.router.run();
}
}
以上是我到目前为止选择的路线。不幸的是,当我转到上面的示例url时,页面会加载错误,而不是正确的/#/stop/1/100032/
。
任何帮助将不胜感激。
您是否曾找到解决方案? – Chad