在定义Backbone.js的路由器基本URL [英] Define a base url in Backbone.js router
问题描述
我希望能够指定一个基本URL我所有的路线发展。一些开发者有机器安装到了子目录使用的应用程序坐在Webroot公司的来代替。
我想只有一次定义这些路线。
代替:
路线:{
汤姆斯子目录/用户:init_users
}
我想:
路线:{
/用户:init_users
}
和能够指定baseURL时为安装,这样我可以很容易使整个安装工作。
现在,我通过定义使用括号的语法,以保持动态密钥的路由对象,并分配了到路由里面的路由属性强迫他们。我在想,如果有一个更清洁的方式。
my_routes = {};
my_routes [window.webroot +'/用户'] ='init_users';MyRoute = Backbone.Router.extend({路线:my_routes})
您可以使用 Backbone.history.start 这样
Backbone.history.start({
pushState的:真实,
根:/公/搜索/
});
I want to be able to specify a base url for all my routes for development. Some of the devs have machines setup to work out of subdirectories instead of the application sitting at the webroot. I would like to only define these routes once. Instead of: routes: { "toms-subdirectory/users": "init_users" } I would like:
routes: {
"/users": "init_users"
}
and be able to specify a baseurl for that installation so I could easily make it work across installs.
Right now I'm forcing them by defining a route object using bracket syntax to keep the dynamic keys and assigning that to the routes property inside the route. I was wondering if there is a cleaner way.
my_routes = {};
my_routes[window.webroot + '/users'] = 'init_users';
MyRoute = Backbone.Router.extend({ routes: my_routes })
You can use Backbone.history.start like this
Backbone.history.start({
pushState: true,
root: "/public/search/"
});
这篇关于在定义Backbone.js的路由器基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!