我试图让使用Parse.com的parse.js框架建立网站。包含在框架Parse.Router(Backbone.Router的一个分支,但似乎在执行中略有不同,但我可能是错的)。Parse.Router - 浏览器刷新按钮返回到index.html的
我有事情运作良好,但我遇到问题来了,当我很喜欢“本地主机/根/简介”页面上,我点击刷新按钮,我得到一个404错误。经过一番搜索之后,我采取了修改我的.htaccess文件的方法,以便这会触发重定向到我的单页应用程序'index.html'。现在的问题是,当此页面重新加载它似乎也重新启动路由器,从而回到我的不是“本地主机/根/ profile文件”“本地主机/根”。谁能告诉我我要去哪里?
这里是我的.htaccess文件:
// .htaccess
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
这里是我的app.js文件中,在我的主index.html文件加载:
// app.js
$(function() {
Parse.$ = jQuery;
Parse.initialize("xxxx", "xxxx");
// * --------------
// * Navigation Bar
// * --------------
var NavigationView = Parse.View.extend({
template: Handlebars.compile($('#navigation-tpl').html()),
events: {
'click .nav-link': 'link'
},
link: function(e) {
// Prevent Default Submit Event
e.preventDefault();
var href = $(e.target).attr('href');
myRouter.navigate(href, { trigger: true });
},
render: function() {
var attributes = this.model.toJSON();
this.$el.html(this.template(attributes));
}
});
// * ---------
// * 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: {
},
render: function(){
var attributes = this.model.toJSON();
this.$el.html(this.template(attributes));
}
});
// * ------------
// * Parse Router
// * ------------
MyRouter = Parse.Router.extend({
// Here you can define some shared variables
initialize: function(options){
console.log("initializing router, options: " + options);
this.user = Parse.User.current();
},
// This runs when we start the router. Just leave it for now.
start: function(){
Parse.history.start({
root: "/root/",
pushState: true,
silent: false
});
this.navigate("", { trigger: true });
},
// This is where you map functions to urls.
// Just add '{{URL pattern}}': '{{function name}}'
routes: {
"": "root",
"profile": "profile",
"*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});
}
},
notFound: function() {
console.log("in the not found");
}
}),
myRouter = new MyRouter();
myRouter.start();
// * --------------------------
// * Add Navigation to the View
// * --------------------------
var user = Parse.User.current();
var navigationView;
if (user) {
navigationView = new NavigationView({model: user});
} else {
navigationView = new NavigationView();
}
navigationView.render();
$('.navigation-container').html(navigationView.el);
});
我是否正确有此设置?这是我的第一次尝试(除了遵循一些教程和阅读文档之外),所以我可能会错过一些非常明显的东西。任何帮助表示赞赏。