admin管理员组文章数量:1417070
I have struggled with this for quite a long time. I'm using Backbone.js along with Require.js. I'm trying to tell Backbone to display a specific view according to the current URL (not hash). My code looks like this:
define(['jquery','underscore','backbone', 'views/manage_pages'], function($, _, Backbone, ManagePages) {
var AppRouter = Backbone.Router.extend({
routes:{
'/new_page': "showPageForm",
'/edit_page': "showPageEditForm",
'*actions': "showPageForm"
},
});
var initialize = function(){
appRouter = new AppRouter;
appRouter.on("route:showPageForm", function(){
console.log('hej');
});
appRouter.on("route:showPageEditForm", function(){
console.log('ho');
});
var page_form = new ManagePages();
Backbone.history.start();
}
return {
initialize: initialize
}
});
So basically when the user goes to it should log <code>hej</code>
and when he goes to it should log <code>ho</code>
. I don't know how to acplish this or even if it is possible. Can anyone help me?
I have struggled with this for quite a long time. I'm using Backbone.js along with Require.js. I'm trying to tell Backbone to display a specific view according to the current URL (not hash). My code looks like this:
define(['jquery','underscore','backbone', 'views/manage_pages'], function($, _, Backbone, ManagePages) {
var AppRouter = Backbone.Router.extend({
routes:{
'/new_page': "showPageForm",
'/edit_page': "showPageEditForm",
'*actions': "showPageForm"
},
});
var initialize = function(){
appRouter = new AppRouter;
appRouter.on("route:showPageForm", function(){
console.log('hej');
});
appRouter.on("route:showPageEditForm", function(){
console.log('ho');
});
var page_form = new ManagePages();
Backbone.history.start();
}
return {
initialize: initialize
}
});
So basically when the user goes to http://example./new_page it should log <code>hej</code>
and when he goes to http://example./editpage it should log <code>ho</code>
. I don't know how to acplish this or even if it is possible. Can anyone help me?
1 Answer
Reset to default 8You could use Backbone's support for HTML5 push-state, which uses the URL path by default (instead of the hash fragment). Just specify it as an option when calling history.start
:
Backbone.history.start({ pushState: true });
(Note that if your application is located in a sub-path under the domain, then you can tell Backbone to use that as the root -- Backbone.history.start({pushState: true, root: "/myapproot/"})
-- although it looks like that's not a concern in your case.)
本文标签: javascriptGetting URL fragment instead of hash in BackbonejsStack Overflow
版权声明:本文标题:javascript - Getting URL fragment instead of hash in Backbone.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745257721a2650201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论