0
我正在使用flatiron/director来做客户端路由。使用director.js,我要为站点根目录定义一个默认路由,它没有#哈希值?
我有这样的路线:
var routes = {
'': function() { loadLandingPage(); },
'/author': function() { author(); }
};
如果我去www.example.com#/作者,它触发了笔者的功能。如果我访问www.example.com#或www.example.com#/,则我的着陆页被加载。
但是,我想为我的网站的根没有#的默认路由。即使我们登陆www.example.com时没有#,我也希望着陆页加载。
我已经浏览了文档,但对于我的生活无法弄清楚。我认为configuration: notfound方法会做我在想什么,但它什么也没做。我试过如下:
var router = Router(routes).configure({ notfound: loadGlobalPage});
和
var router = Router(routes).configure({ notfound: function() {loadGlobalPage();} });
,也读this thread后,我想:
router.notfound = function() {
loadGlobalPage();
};
我也试过无关路由器一个黑客:
function determineIfLandingPage() {
if (window.location.hash == "") {
loadGlobalPage();
window.location.href += "#"
}
}
这有效,但它感觉像一个黑客。
这必须是一个有点常见的用例 - 我如何从我的路由器获得所需的功能?
很好的答案。但你有一个小的错字:)。你能编辑它吗?它应该是route.init(['/'])。初始化中缺少't'。 –
@AnteBraovic谢谢 – towry