Registering a route
$bindary.addRoute() takes a path, an exact string or a
RegExp, plus a viewURL and controllerURL for what to
load when that path matches.
// exact string match
$bindary.addRoute({
path: 'about',
viewURL: 'views/about.html',
controllerURL: 'controllers/about.js'
});
// regex match with a capture group
$bindary.addRoute({
path: /^products\/([^\/]+)$/,
viewURL: 'views/products/$1.html',
controllerURL: 'controllers/products.js'
});
A regex path can carry capture groups and $1, $2 and so on refer to
them in viewURL and controllerURL, so products/chair
loads views/products/chair.html with $1 resolved to
chair. Building that string is entirely up to you, a plain literal like above,
concatenation, a small helper function, whatever suits your project, Bindary only cares about
the final string it receives.
Routes are matched in the order they were added, in $bindary.routes. A catch-all
pattern needs to be registered after the more specific routes or it swallows everything before
they get a chance to match.
$bindary.addRoute({ path: 'home', viewURL: 'views/home.html' });
$bindary.addRoute({ path: /^products\/([^\/]+)$/, viewURL: 'views/products/$1.html' });
$bindary.addRoute({ path: /^([^\/]+)$/, viewURL: 'views/$1.html' }); // catch-all, registered last
dataConnect: false skips the automatic data request that would otherwise fire
when this route loads. It doesn't disable the connection itself, that's controlled by
separate settings covered on Backend,
$bindary.dataSend() still works from a dataConnect: false route,
this only opts out of the automatic one. Leave it out to have that automatic request fire by
default.