2013-12-11 33 views
0

我有一個基於SammyJS的單頁面應用程序運行在http://[mydomain]/[myapp]/[subPath]下。無論[subPath]是什麼,該服務器都配置爲返回相同的HTML「啓動」頁面,即路由配置了子路徑的通配符。如何強制與SammyJS初始導航

由於我希望用戶能夠爲應用程序中的特定子路徑添加書籤(例如,「/ orders/123」),我需要在加載「啓動」頁面時強制客戶端導航到該子路徑。做這個的最好方式是什麼?在設置我的應用程序之後,我嘗試了window.location.pathname = window.location.pathname,但這只是導致無限循環重新導航到頁面。

回答

0

當創建SammyJS應用,簡單地傳遞window.location.pathnamerun()方法如下:

Sammy(function() { 
    this.get(/* custom route */, function (context) { 
      // ... handle navigation ... 
    }); 
}).run(window.location.pathname); // Voila!