【问题标题】:Absolute URL routing with sammy.js使用 sammy.js 进行绝对 URL 路由
【发布时间】:2012-08-08 06:32:35
【问题描述】:

我有一个绝对网址:

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

我使用 Sammy.js 进行路由,但它不会路由它。但是,很高兴路由同一 URL 的相对版本:

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

我怎样才能以同样的方式让 sammy route 成为绝对版本?

【问题讨论】:

    标签: routing sammy.js


    【解决方案1】:

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

    然后用 Sammy 捕获路由并使用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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-09
      相关资源
      最近更新 更多