3 var MoreRouting
= scope
.MoreRouting
= scope
.MoreRouting
|| {};
12 * Retrieves (or builds) the singleton `Route` for the given path expression or
15 * Paths begin with `/`; anything else is considered a name.
17 * For convenience, `Route` objects can also be passed (and will be returned) -
18 * this can be used as a route coercion function.
20 * @param {String|MoreRouting.Route} pathOrName
21 * @param {MoreRouting.Route} parent
22 * @return {MoreRouting.Route}
24 MoreRouting
.getRoute
= function getRoute(pathOrName
, parent
) {
25 if (typeof pathOrName
!== 'string') return pathOrName
;
26 if (this.isPath(pathOrName
)) {
27 return this.getRouteByPath(pathOrName
, parent
);
29 return this.getRouteByName(pathOrName
);
34 * Retrieves (or builds) the singleton `Route` for the given path expression.
36 * @param {String} path
37 * @param {MoreRouting.Route} parent
38 * @return {MoreRouting.Route}
40 MoreRouting
.getRouteByPath
= function getRouteByPath(path
, parent
) {
41 var fullPath
= (parent
? parent
.fullPath
: '') + path
;
42 if (!routesByPath
[fullPath
]) {
43 routesByPath
[fullPath
] = new this.Route(path
, parent
);
44 this.driver
.manageRoute(routesByPath
[fullPath
]);
46 return routesByPath
[fullPath
];
50 * Retrieves the route registered via `name`.
52 * @param {String} name
53 * @return {MoreRouting.Route}
55 MoreRouting
.getRouteByName
= function getRouteByName(name
) {
56 var path
= pathsByName
[name
];
58 throw new Error('No route named "' + name
+ '" has been registered');
60 return this.getRouteByPath(path
);
64 * @param {String} path
65 * @return {MoreRouting.Route} The newly registered route.
67 MoreRouting
.registerNamedRoute
= function registerNamedRoute(name
, path
, parent
) {
68 if (pathsByName
[name
]) {
70 'Overwriting route named "' + name
+ '" with path:', path
,
71 'previously:', pathsByName
[name
]);
73 var route
= this.getRouteByPath(path
, parent
);
74 pathsByName
[name
] = route
.fullPath
;
79 MoreRouting
.urlFor
= function urlFor(pathOrName
, params
) {
80 return this.getRoute(pathOrName
).urlFor(params
);
83 MoreRouting
.navigateTo
= function navigateTo(pathOrName
, params
) {
84 return this.getRoute(pathOrName
).navigateTo(params
);
87 MoreRouting
.isCurrentUrl
= function isCurrentUrl(pathOrName
, params
) {
88 return this.getRoute(pathOrName
).isCurrentUrl(params
);
96 MoreRouting
.isPath
= function isPath(pathOrName
) {
97 return this.Route
.isPath(pathOrName
);
101 * @param {...String} paths
103 MoreRouting
.joinPath
= function joinPath(paths
) {
104 return this.Route
.joinPath
.apply(this.Route
, arguments
);
110 Object
.defineProperty(MoreRouting
, 'driver', {
111 get: function getDriver() {
113 throw new Error('No routing driver configured. Did you forget <more-routing-config>?');
117 set: function setDriver(newDriver
) {
119 console
.warn('Changing routing drivers is not supported, ignoring. You should have only one <more-routing-config> on the page!');