簡體   English   中英

使用director.js,如何為其中沒有#哈希的網站根定義默認路由?

[英]Using director.js, how do I define a default route for the site root which has no # hash in it?

我正在使用熨斗/導演進行客戶端路由。

我有如下路線:

  var routes = {
    '': function() { loadLandingPage(); },
    '/author': function() { author(); }
  };

如果我訪問www.example.com#/ author,它將觸發作者功能。 如果我訪問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();} });

並且在閱讀了該線程之后 ,我嘗試了:

router.notfound = function() {
    loadGlobalPage();
};

我還嘗試了與路由器無關的黑客:

function determineIfLandingPage() {
    if (window.location.hash == "") {
        loadGlobalPage();
        window.location.href += "#"
    }
}

這行得通,但感覺像是在砍死。

這一定是一個常見的用例-如何從路由器中獲得所需的功能?

從文檔中: redirect方法將解決此問題。

如果在URL中找不到'/#/'route.init(['/'])將重定向到路由/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM