在 Backbone.js 路由器中定义一个基本 url [英] Define a base url in Backbone.js router
问题描述
我希望能够为我的所有开发路线指定一个基本网址.一些开发人员将机器设置为在子目录中工作,而不是位于 webroot 的应用程序.我只想定义这些路线一次.代替:路线:{toms-子目录/用户":init_users"}我想:
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"
}
并且能够为该安装指定一个 baseurl,以便我可以轻松地使其跨安装工作.
and be able to specify a baseurl for that installation so I could easily make it work across installs.
现在我通过使用括号语法定义路由对象来强制它们,以保留动态键并将其分配给路由内的 routes 属性.我想知道是否有更清洁的方法.
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 })
推荐答案
您可以使用 Backbone.history.start 像这样
Backbone.history.start({
pushState: true,
root: "/public/search/"
});
这篇关于在 Backbone.js 路由器中定义一个基本 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!