深度链接时,Parse.Router无法找到参考文件

时间:2015-08-21 09:18:34

标签: javascript .htaccess parse-platform routing backbone-routing

我一直在使用parse.js构建单页网站慢慢找到自己的方式,其中包括Parse.Router。

今天我终于克服了点击浏览器刷新按钮导致404错误修改我的.htaccess文件的问题。

我现在面临的问题是,如果我导航说" localhost / root / profile / edit"然后单击浏览器刷新按钮,我的页面找不到,但我的资源都没有正确加载。事实上,我在我的控制台中收到此错误:

SyntaxError: expected expression, got '<'

我可以在控制台中看到它正在尝试从&#34; localhost / root / profile / js / file.js&#34;加载我的文件。而不是他们在我的根目录中的位置。奇怪的是,当我点击&#34; localhost / root / profile&#34;一切都很好。只是更深层次,它不起作用。

这是我的.htaccess文件:

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^.*/index.php
    RewriteRule ^(.*)index.php$ $1 [R,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/index\.php

    RewriteRule (.*) index.php
</ifModule>

这是我的app.js文件,加载在我的主index.php文件中:

// app.js
$(function() {
    Parse.$ = jQuery;

    Parse.initialize("xxxx", "xxxx");

    // * ---------
    // * Root View
    // * ---------
    var RootView = Parse.View.extend({
        template: Handlebars.compile($('#root-tpl').html()),
        events:{
        },
        render: function() {
            this.$el.html(this.template());
        }
    });

    // * ------------
    // * Profile View
    // * ------------
    var ProfileView = Parse.View.extend({
        template: Handlebars.compile($('#profile-tpl').html()),
        events: {
            'click .edit-profile': 'edit'
        },
        edit: function(){
            Parse.history.navigate("profile/edit", true);
            return false;
        },
        render: function(){
            var attributes = this.model.toJSON();
            this.$el.html(this.template(attributes));
        }
    });

    // * ------------
    // * Edit View
    // * ------------
    var EditView = Parse.View.extend({
        template: Handlebars.compile($('#edit-profile-tpl').html()),
        render: function(){
            var attributes = this.model.toJSON();
            this.$el.html(this.template(attributes));
        }
    });

    // * ------------
    // * Parse Router
    // * ------------
    var MyRouter = Parse.Router.extend({
        initialize: function(options){
            this.user = Parse.User.current();
            $("body").on("click","a:not(a[data-bypass])",function(e){
                // block the default link behavior
                e.preventDefault();
                // take the href of the link clicked
                var href = $(this).attr("href");
                // pass this link to Parse
                Parse.history.navigate(href,true);
            });
        },      
        start: function(){
            Parse.history.start({
                root: App.ROOT,
                pushState:  true,
                silent:     false
            });
        },
        routes: {
            "":             "root",
            "profile":      "profile",
            "profile/edit": "editProfile",
            "*nf":          "notFound"
        },
        root: function() {
            var rootView = new RootView();
            rootView.render();
            $('.main-container').html(rootView.el);
        },
        profile: function() {
            if (this.user) {
                var profileView = new ProfileView({ model: this.user });
                profileView.render();
                $('.main-container').html(profileView.el);
            }  else {
                this.navigate("root", {trigger: true});
            }
        },
        editProfile: function() {
            var editView = new EditView({ model: this.user });
            editView.render();
            $('.main-container').html(editView.el);
        },
        notFound: function() {
            console.log("in the not found");
        }
    }),
    var App = {
        ROOT: "/root/",
        router: new MyRouter()
    };
    App.router.start();
});

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

这最终成为我的源文件的src路径问题。

我正在请求我的源文件:

<link href="css/bootstrap.min.css" rel="stylesheet">

当我本来应该请求他们时:

<link href="/root/css/bootstrap.min.css" rel="stylesheet">

一旦我做了这个调整,一切现在看起来都按预期工作了。

相关问题