0

嗨,我创建了一个带有击倒、放大和 sammy 的水疗中心。

如果我现在单击如下链接:

#/page?s=About

它链接到 url.de/subdirectory/#/page?s=About 这是正确的,但控制台会触发以下错误: GET url.de/About 404 (Not Found) 因为它应该是: url.de/subdirectory/About

我的萨米代码是:

var app=$.sammy(function () {

        // define prexecutes

        // update parameters in appModel from request for all routes
        this.before('', function() {
            //setParameters(this);
        });

        // authenticate on any page except for login and logout routes
        this.before({except: {path:/\/(login|logout|hp)/}}, function() {

        });

        // actual routes

        // home

        this.get('#/', function() {
            appModel.page("home");
            return false;
        });

        // content

        this.get('#/page', function(eventContext) {

            content(eventContext);
        });

    });

    app.run('#/');

如何让 sammy 不忽略我的网站所在的子目录?

4

2 回答 2

0

您可以尝试使用像这样的另一个自定义路由定义

this.get('#/page/:s', function(eventContext) { // where s is parametre

            content(eventContext);
        });

也使用这样的网址

#/page/About  // it will read 'About' as value of parameter 's'

代替

#/page?s=About

希望这可以帮助

于 2013-11-10T11:41:56.420 回答
0

我最近自己也遇到过类似的情况。我找不到任何允许 Sammy.js 路由到子目录的配置选项或解决方法。我的解决方案是在托管我的应用程序的服务器上创建一个虚拟主机,并将子目录作为子域,以便将应用程序放在文档根目录中。在您的情况下,虚拟服务器将从 映射url.de/subdir/Aboutsubdir.url.de/About。我意识到这对您来说可能是不可能的(因为我不知道您对托管环境有多少控制权),但这让我很快再次行动起来。希望这可以帮助。

PS 顺便说一句,我刚刚浏览了位于https://github.com/quirkey/sammy的 Sammy.js 源代码,看来子目录已被删除(错误)以修复 IE 怪癖。 https://github.com/quirkey/sammy/blob/master/lib/sammy.js#L301可能是问题所在。

于 2013-11-13T16:15:55.177 回答