用户单击链接时URL路由不起作用

时间:2016-03-01 15:21:53

标签: javascript jquery html

我正在尝试修改我们拥有的网络应用程序,而且我不确定我是否可以执行所请求的内容。我的老板希望能够点击电子邮件中的链接,让我们的内部公司Web应用程序直接进入提供的URL末尾标识的页面。

如果我第一次点击下面的链接,它会转到我们的网络应用程序的索引页面。如果我打开Web应用程序并再次单击该链接,它将转到URL末尾标识的正确页面。

http://mycompanyweb.com/handbook/mycompanyprocess/#/rt/softwate/9.13_UpdateSDP

我尝试添加一个init(),认为这是应用程序在生命周期中的第一个位置,我只看到该点的这一部分(http://mycompanyweb.com/handbook/mycompanyprocess/)。这让我相信浏览器在首次打开#时会删除所有内容。那是对的吗?我可以做些什么来让我们的Web应用程序在用户第一次点击链接时直接转到文档,而不打开Web应用程序?

http://mycompanyweb.com/handbook/mycompanyprocess/ - Base URL

#/rt    - Used by our javascript engine to determine which path to take 
(dev or production).

/software/9.13_UpdateSDP    - Logical path to a web page named 6.034_UpdateSDP.htm

我们的引擎根据URL确定路由的位置。我假设第二次点击一个链接进入正确的页面是因为引擎已加载(如果浏览器在第二次点击时保持打开状态)。

$(document).ready(function () {
// Define the routes.
Path.map("#/:program").to(function () {
    var program = this.params['program'];

    if (program == "search") {
        $("#mainContent").load("search.html");
    }
    else {
        $("#mainContent").load("views/onepageprocess.html");
    }

    $("#subheader").html("");

    $("#headerLevelTwoBreadcrumbLink").html("");
}).enter(setPageActions);

Path.map("#/:program/:swimlane").to(function () {
    localStorage.removeItem("SearchString");

    var swimlane = this.params['swimlane'];

    var view = "views/" + swimlane + ".html";

    $("#mainContent").load(view);

}).enter(setPageActions);

// Sends all links to the level three view and updates the breadcrumb.
Path.map("#/:program/:swimlane/:page").to(function () {
    var page = this.params['page'];

var url = "views/levelthree/" + page.replace("", "") + ".htm";

var levelThreeTitle = "";

    $.get(url)
    .done(function () {
        // Nothing here at this time...
    }).fail(function () {
        url = "views/levelthree/badurlpage.htm";

        levelThreeTitle = "Page Unavailable";
    }).always(function (data) {
        $("#subheader").html("");

        level_three_breadcrumb = "views/breadcrumbs/breadcrumb_link.html";

        $("#headerLevelTwoBreadcrumbLink").load(level_three_breadcrumb);

        $("#headerLevelThreeBreadcrumb").html("");

        $('#headerLevelThreeBreadcrumb').append('<img src="images/Chevron.gif" />');

        if (data.status != "404") {
            $("#headerLevelThreeBreadcrumb").append(retrieveStorageItem("LevelThreeSubheader"));
        }

        $("#mainContent").load(url);
    });

}).enter(setPageActions);

// Set a "root route". User will be automatically re-directed here.  The definition
// below tells PathJS to load this route automatically if one isn't provided.
Path.root("#/rt");

// Start the path.js listener.
Path.listen();
});

我可以做些什么来让我们的网络应用程序在用户第一次点击链接时直接转到文档,而不打开Web应用程序?

1 个答案:

答案 0 :(得分:0)

如果有人碰到这样的事情,我发现我公司的服务器在身份验证时在URL中删除#。我将修改我的应用程序,以便不在URL中使用哈希标记来修复它。

相关问题