|
1 | 1 | /** @publicapi @module state */ /** */
|
2 |
| -import { applyPairs, extend, identity, inherit, mapObj, noop, Obj, omit, tail, values } from '../common/common'; |
| 2 | +import { applyPairs, extend, identity, inherit, mapObj, noop, Obj, omit, tail, values, copy } from '../common/common'; |
3 | 3 | import { isArray, isDefined, isFunction, isString } from '../common/predicates';
|
4 | 4 | import { stringify } from '../common/strings';
|
5 | 5 | import { is, pattern, pipe, prop, val } from '../common/hof';
|
@@ -57,17 +57,20 @@ function dataBuilder(state: StateObject) {
|
57 | 57 |
|
58 | 58 | const getUrlBuilder = ($urlMatcherFactoryProvider: UrlMatcherFactory, root: () => StateObject) =>
|
59 | 59 | function urlBuilder(stateObject: StateObject) {
|
60 |
| - const state: StateDeclaration = stateObject.self; |
| 60 | + let stateDec: StateDeclaration = stateObject.self; |
61 | 61 |
|
62 | 62 | // For future states, i.e., states whose name ends with `.**`,
|
63 | 63 | // match anything that starts with the url prefix
|
64 |
| - if (state && state.url && state.name && state.name.match(/\.\*\*$/)) { |
65 |
| - state.url += '{remainder:any}'; // match any path (.*) |
| 64 | + if (stateDec && stateDec.url && stateDec.name && stateDec.name.match(/\.\*\*$/)) { |
| 65 | + const newStateDec: StateDeclaration = {}; |
| 66 | + copy(stateDec, newStateDec); |
| 67 | + newStateDec.url += '{remainder:any}'; // match any path (.*) |
| 68 | + stateDec = newStateDec; |
66 | 69 | }
|
67 | 70 |
|
68 | 71 | const parent = stateObject.parent;
|
69 |
| - const parsed = parseUrl(state.url); |
70 |
| - const url = !parsed ? state.url : $urlMatcherFactoryProvider.compile(parsed.val, { state }); |
| 72 | + const parsed = parseUrl(stateDec.url); |
| 73 | + const url = !parsed ? stateDec.url : $urlMatcherFactoryProvider.compile(parsed.val, { state: stateDec }); |
71 | 74 |
|
72 | 75 | if (!url) return null;
|
73 | 76 | if (!$urlMatcherFactoryProvider.isMatcher(url)) throw new Error(`Invalid url '${url}' in state '${stateObject}'`);
|
|
0 commit comments