繁体   English   中英

深度链接时Parse.Router找不到参考文件

[英]Parse.Router cannot find reference files when deep link

我一直在慢慢寻找使用parse.js(包括Parse.Router)构建单页网站的方式。

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

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

SyntaxError: expected expression, got '<'

我可以在控制台中看到它正在尝试从“ localhost / root / profile / js / file.js”而不是从位于我的根目录中的文件加载文件。 奇怪的是,当我单击“本地主机/根目录/配置文件”上的刷新时,一切都加载正常。 仅深一层,它不起作用。

这是我的.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();
});

任何帮助是极大的赞赏。

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

我正在请求我的源文件,例如:

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

当我应该像这样要求他们时:

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

一旦进行了此调整,现在一切似乎都可以按预期进行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM