2 var MoreRouting = scope.MoreRouting = scope.MoreRouting || {};
11 * Retrieves (or builds) the singleton `Route` for the given path expression or
14 * Paths begin with `/`; anything else is considered a name.
16 * For convenience, `Route` objects can also be passed (and will be returned) -
17 * this can be used as a route coercion function.
19 * @param {String|MoreRouting.Route} pathOrName
20 * @param {MoreRouting.Route} parent
21 * @return {MoreRouting.Route}
23 MoreRouting.getRoute = function getRoute(pathOrName, parent) {
24 if (typeof pathOrName !== 'string') return pathOrName;
25 if (this.isPath(pathOrName)) {
26 return this.getRouteByPath(pathOrName, parent);
28 return this.getRouteByName(pathOrName);
33 * Retrieves (or builds) the singleton `Route` for the given path expression.
35 * @param {String} path
36 * @param {MoreRouting.Route} parent
37 * @return {MoreRouting.Route}
39 MoreRouting.getRouteByPath = function getRouteByPath(path, parent) {
40 var fullPath = (parent ? parent.fullPath : '') + path;
41 if (!routesByPath[fullPath]) {
42 routesByPath[fullPath] = new this.Route(path, parent);
43 this.driver.manageRoute(routesByPath[fullPath]);
45 return routesByPath[fullPath];
49 * Retrieves the route registered via `name`.
51 * @param {String} name
52 * @return {MoreRouting.Route}
54 MoreRouting.getRouteByName = function getRouteByName(name) {
55 var path = pathsByName[name];
57 throw new Error('No route named "' + name + '" has been registered');
59 return this.getRouteByPath(path);
63 * @param {String} path
64 * @return {MoreRouting.Route} The newly registered route.
66 MoreRouting.registerNamedRoute = function registerNamedRoute(name, path, parent) {
67 if (pathsByName[name]) {
69 'Overwriting route named "' + name + '" with path:', path,
70 'previously:', pathsByName[name]);
72 var route = this.getRouteByPath(path, parent);
73 pathsByName[name] = route.fullPath;
78 MoreRouting.urlFor = function urlFor(pathOrName, params) {
79 return this.getRoute(pathOrName).urlFor(params);
82 MoreRouting.navigateTo = function navigateTo(pathOrName, params) {
83 return this.getRoute(pathOrName).navigateTo(params);
86 MoreRouting.isCurrentUrl = function isCurrentUrl(pathOrName, params) {
87 return this.getRoute(pathOrName).isCurrentUrl(params);
95 MoreRouting.isPath = function isPath(pathOrName) {
96 return this.Route.isPath(pathOrName);
100 * @param {...String} paths
102 MoreRouting.joinPath = function joinPath(paths) {
103 return this.Route.joinPath.apply(this.Route, arguments);
109 Object.defineProperty(MoreRouting, 'driver', {
110 get: function getDriver() {
112 throw new Error('No routing driver configured. Did you forget <more-routing-config>?');
116 set: function setDriver(newDriver) {
118 console.warn('Changing routing drivers is not supported, ignoring. You should have only one <more-routing-config> on the page!');