2012-08-10 52 views
1

路由我有一个的绝对网址:绝对URL与sammy.js

<a href="https://circleci.com/docs/configuration">configuration</a> 

我用Sammy.js路由,但不会将其路由。然而,它很高兴地路由相同的URL的相对版本:

<a href="/docs/configuration">configuration</a> 

我怎样才能使sammy路线的绝对版本以同样的方式?

回答

0

你仍然可以使用哈希在href,即href="#ESPN"

然后捕获与萨米路线,并使用location.assign方法加载新的URL或检索文件:

Sammy(function() { 
    /* Top-bar navigation requests 
    */ 
    this.get("#:view", function() { 
     switch (this.params.view) {    
      case "ESPN": 
       location.assign("http://www.espn.com") 
       break;  
     }; 
    }); 

    /* Reporting Excel requests 
    */ 
    this.get("#Reporting/Excel/:type/:audience/:unitID/:departmentID", function() { 
     location.assign("Report/Excel?" + 
      "Type=" + this.params.type + "&" + 
      "Audience=" + this.params.audience + "&" + 
      "UnitID=" + this.params.unitID + "&" + 
      "DepartmentID=" + this.params.departmentID 
     ); 
    }); 
}).run();