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 })
The URL found in the address bar of the front page of a website is its base URL. In other words, the common prefix found while navigating inside a given website is known as the base URL. One can select a base URL from the list of those available with help of the URL general properties page.
To get the base URL in JavaScript, we use the window. location. origin and window. location.
There's nothing in the Android URI class that gives you the base URL directly- As gnuf suggests, you'd have to construct it as the protocol + getHost(). The string parsing way might be easier and let you avoid stuffing everything in a try/catch block.
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
You can use Backbone.history.start like this
Backbone.history.start({
pushState: true,
root: "/public/search/"
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With