@ngxs/router-plugin 3.7.4 → 3.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,738 +1,643 @@
1
1
  import { NgZone, Injectable, NgModule } from '@angular/core';
2
2
  import { Store, Action, Selector, State, NgxsModule } from '@ngxs/store';
3
3
  import { __decorate, __metadata } from 'tslib';
4
- import { NavigationStart, RoutesRecognized, ResolveEnd, NavigationCancel, NavigationError, NavigationEnd, Router, UrlSerializer } from '@angular/router';
5
- import { LocationStrategy, Location } from '@angular/common';
6
- import { isAngularInTestMode } from '@ngxs/store/internals';
4
+ import { NavigationStart, RoutesRecognized, ResolveEnd, NavigationCancel, NavigationError, NavigationEnd, Router } from '@angular/router';
7
5
  import { Subscription } from 'rxjs';
8
- import { first } from 'rxjs/operators';
9
6
 
10
- /**
11
- * @fileoverview added by tsickle
12
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
13
- */
14
- /**
15
- * Public event api of the router
16
- */
17
- class Navigate {
18
- /**
19
- * @param {?} path
20
- * @param {?=} queryParams
21
- * @param {?=} extras
22
- */
23
- constructor(path, queryParams, extras) {
24
- this.path = path;
25
- this.queryParams = queryParams;
26
- this.extras = extras;
27
- }
28
- /**
29
- * @return {?}
30
- */
31
- static get type() {
32
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
33
- return '[Router] Navigate';
34
- }
35
- }
36
- if (false) {
37
- /** @type {?} */
38
- Navigate.prototype.path;
39
- /** @type {?} */
40
- Navigate.prototype.queryParams;
41
- /** @type {?} */
42
- Navigate.prototype.extras;
43
- }
44
- /**
45
- *
46
- * Angular Routers internal state events
47
- *
48
- */
49
- /**
50
- * An action dispatched when the router navigates.
51
- * @template T
52
- */
53
- class RouterNavigation {
54
- /**
55
- * @param {?} routerState
56
- * @param {?} event
57
- * @param {?=} trigger
58
- */
59
- constructor(routerState, event, trigger = 'none') {
60
- this.routerState = routerState;
61
- this.event = event;
62
- this.trigger = trigger;
63
- }
64
- /**
65
- * @return {?}
66
- */
67
- static get type() {
68
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
69
- return '[Router] RouterNavigation';
70
- }
71
- }
72
- if (false) {
73
- /** @type {?} */
74
- RouterNavigation.prototype.routerState;
75
- /** @type {?} */
76
- RouterNavigation.prototype.event;
77
- /** @type {?} */
78
- RouterNavigation.prototype.trigger;
79
- }
80
- /**
81
- * An action dispatched when the router cancel navigation.
82
- * @template T, V
83
- */
84
- class RouterCancel {
85
- /**
86
- * @param {?} routerState
87
- * @param {?} storeState
88
- * @param {?} event
89
- * @param {?=} trigger
90
- */
91
- constructor(routerState, storeState, event, trigger = 'none') {
92
- this.routerState = routerState;
93
- this.storeState = storeState;
94
- this.event = event;
95
- this.trigger = trigger;
96
- }
97
- /**
98
- * @return {?}
99
- */
100
- static get type() {
101
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
102
- return '[Router] RouterCancel';
103
- }
104
- }
105
- if (false) {
106
- /** @type {?} */
107
- RouterCancel.prototype.routerState;
108
- /** @type {?} */
109
- RouterCancel.prototype.storeState;
110
- /** @type {?} */
111
- RouterCancel.prototype.event;
112
- /** @type {?} */
113
- RouterCancel.prototype.trigger;
114
- }
115
- /**
116
- * An action dispatched when the router errors.
117
- * @template T, V
118
- */
119
- class RouterError {
120
- /**
121
- * @param {?} routerState
122
- * @param {?} storeState
123
- * @param {?} event
124
- * @param {?=} trigger
125
- */
126
- constructor(routerState, storeState, event, trigger = 'none') {
127
- this.routerState = routerState;
128
- this.storeState = storeState;
129
- this.event = event;
130
- this.trigger = trigger;
131
- }
132
- /**
133
- * @return {?}
134
- */
135
- static get type() {
136
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
137
- return '[Router] RouterError';
138
- }
139
- }
140
- if (false) {
141
- /** @type {?} */
142
- RouterError.prototype.routerState;
143
- /** @type {?} */
144
- RouterError.prototype.storeState;
145
- /** @type {?} */
146
- RouterError.prototype.event;
147
- /** @type {?} */
148
- RouterError.prototype.trigger;
149
- }
150
- /**
151
- * An action dispatched when the `ResolveEnd` event is triggered.
152
- * @template T
153
- */
154
- class RouterDataResolved {
155
- /**
156
- * @param {?} routerState
157
- * @param {?} event
158
- * @param {?=} trigger
159
- */
160
- constructor(routerState, event, trigger = 'none') {
161
- this.routerState = routerState;
162
- this.event = event;
163
- this.trigger = trigger;
164
- }
165
- /**
166
- * @return {?}
167
- */
168
- static get type() {
169
- // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
170
- return '[Router] RouterDataResolved';
171
- }
172
- }
173
- if (false) {
174
- /** @type {?} */
175
- RouterDataResolved.prototype.routerState;
176
- /** @type {?} */
177
- RouterDataResolved.prototype.event;
178
- /** @type {?} */
179
- RouterDataResolved.prototype.trigger;
7
+ /**
8
+ * @fileoverview added by tsickle
9
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
+ */
11
+ /**
12
+ * Public event api of the router
13
+ */
14
+ class Navigate {
15
+ /**
16
+ * @param {?} path
17
+ * @param {?=} queryParams
18
+ * @param {?=} extras
19
+ */
20
+ constructor(path, queryParams, extras) {
21
+ this.path = path;
22
+ this.queryParams = queryParams;
23
+ this.extras = extras;
24
+ }
25
+ /**
26
+ * @return {?}
27
+ */
28
+ static get type() {
29
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
30
+ return '[Router] Navigate';
31
+ }
32
+ }
33
+ if (false) {
34
+ /** @type {?} */
35
+ Navigate.prototype.path;
36
+ /** @type {?} */
37
+ Navigate.prototype.queryParams;
38
+ /** @type {?} */
39
+ Navigate.prototype.extras;
40
+ }
41
+ /**
42
+ *
43
+ * Angular Routers internal state events
44
+ *
45
+ */
46
+ /**
47
+ * An action dispatched when the router navigates.
48
+ * @template T
49
+ */
50
+ class RouterNavigation {
51
+ /**
52
+ * @param {?} routerState
53
+ * @param {?} event
54
+ * @param {?=} trigger
55
+ */
56
+ constructor(routerState, event, trigger = 'none') {
57
+ this.routerState = routerState;
58
+ this.event = event;
59
+ this.trigger = trigger;
60
+ }
61
+ /**
62
+ * @return {?}
63
+ */
64
+ static get type() {
65
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
66
+ return '[Router] RouterNavigation';
67
+ }
68
+ }
69
+ if (false) {
70
+ /** @type {?} */
71
+ RouterNavigation.prototype.routerState;
72
+ /** @type {?} */
73
+ RouterNavigation.prototype.event;
74
+ /** @type {?} */
75
+ RouterNavigation.prototype.trigger;
76
+ }
77
+ /**
78
+ * An action dispatched when the router cancel navigation.
79
+ * @template T, V
80
+ */
81
+ class RouterCancel {
82
+ /**
83
+ * @param {?} routerState
84
+ * @param {?} storeState
85
+ * @param {?} event
86
+ * @param {?=} trigger
87
+ */
88
+ constructor(routerState, storeState, event, trigger = 'none') {
89
+ this.routerState = routerState;
90
+ this.storeState = storeState;
91
+ this.event = event;
92
+ this.trigger = trigger;
93
+ }
94
+ /**
95
+ * @return {?}
96
+ */
97
+ static get type() {
98
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
99
+ return '[Router] RouterCancel';
100
+ }
101
+ }
102
+ if (false) {
103
+ /** @type {?} */
104
+ RouterCancel.prototype.routerState;
105
+ /** @type {?} */
106
+ RouterCancel.prototype.storeState;
107
+ /** @type {?} */
108
+ RouterCancel.prototype.event;
109
+ /** @type {?} */
110
+ RouterCancel.prototype.trigger;
111
+ }
112
+ /**
113
+ * An action dispatched when the router errors.
114
+ * @template T, V
115
+ */
116
+ class RouterError {
117
+ /**
118
+ * @param {?} routerState
119
+ * @param {?} storeState
120
+ * @param {?} event
121
+ * @param {?=} trigger
122
+ */
123
+ constructor(routerState, storeState, event, trigger = 'none') {
124
+ this.routerState = routerState;
125
+ this.storeState = storeState;
126
+ this.event = event;
127
+ this.trigger = trigger;
128
+ }
129
+ /**
130
+ * @return {?}
131
+ */
132
+ static get type() {
133
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
134
+ return '[Router] RouterError';
135
+ }
136
+ }
137
+ if (false) {
138
+ /** @type {?} */
139
+ RouterError.prototype.routerState;
140
+ /** @type {?} */
141
+ RouterError.prototype.storeState;
142
+ /** @type {?} */
143
+ RouterError.prototype.event;
144
+ /** @type {?} */
145
+ RouterError.prototype.trigger;
146
+ }
147
+ /**
148
+ * An action dispatched when the `ResolveEnd` event is triggered.
149
+ * @template T
150
+ */
151
+ class RouterDataResolved {
152
+ /**
153
+ * @param {?} routerState
154
+ * @param {?} event
155
+ * @param {?=} trigger
156
+ */
157
+ constructor(routerState, event, trigger = 'none') {
158
+ this.routerState = routerState;
159
+ this.event = event;
160
+ this.trigger = trigger;
161
+ }
162
+ /**
163
+ * @return {?}
164
+ */
165
+ static get type() {
166
+ // NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
167
+ return '[Router] RouterDataResolved';
168
+ }
169
+ }
170
+ if (false) {
171
+ /** @type {?} */
172
+ RouterDataResolved.prototype.routerState;
173
+ /** @type {?} */
174
+ RouterDataResolved.prototype.event;
175
+ /** @type {?} */
176
+ RouterDataResolved.prototype.trigger;
180
177
  }
181
178
 
182
- /**
183
- * @fileoverview added by tsickle
184
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
185
- */
186
- /**
187
- * @abstract
188
- * @template T
189
- */
190
- class RouterStateSerializer {
191
- }
192
- if (false) {
193
- /**
194
- * @abstract
195
- * @param {?} routerState
196
- * @return {?}
197
- */
198
- RouterStateSerializer.prototype.serialize = function (routerState) { };
199
- }
200
- /**
201
- * @record
202
- */
203
- function SerializedRouterStateSnapshot() { }
204
- if (false) {
205
- /** @type {?} */
206
- SerializedRouterStateSnapshot.prototype.root;
207
- /** @type {?} */
208
- SerializedRouterStateSnapshot.prototype.url;
209
- }
210
- class DefaultRouterStateSerializer {
211
- /**
212
- * @param {?} routerState
213
- * @return {?}
214
- */
215
- serialize(routerState) {
216
- return {
217
- root: this.serializeRoute(routerState.root),
218
- url: routerState.url
219
- };
220
- }
221
- /**
222
- * @private
223
- * @param {?} route
224
- * @return {?}
225
- */
226
- serializeRoute(route) {
227
- /** @type {?} */
228
- const children = route.children.map((/**
229
- * @param {?} c
230
- * @return {?}
231
- */
232
- c => this.serializeRoute(c)));
233
- return {
234
- url: route.url,
235
- params: route.params,
236
- queryParams: route.queryParams,
237
- fragment: route.fragment,
238
- data: route.data,
239
- outlet: route.outlet,
240
- component: null,
241
- routeConfig: null,
242
- root: (/** @type {?} */ (null)),
243
- parent: null,
244
- firstChild: children[0],
245
- children: children,
246
- pathFromRoot: (/** @type {?} */ (null)),
247
- paramMap: route.paramMap,
248
- queryParamMap: route.queryParamMap,
249
- toString: route.toString
250
- };
251
- }
179
+ /**
180
+ * @fileoverview added by tsickle
181
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
182
+ */
183
+ /**
184
+ * @abstract
185
+ * @template T
186
+ */
187
+ class RouterStateSerializer {
188
+ }
189
+ if (false) {
190
+ /**
191
+ * @abstract
192
+ * @param {?} routerState
193
+ * @return {?}
194
+ */
195
+ RouterStateSerializer.prototype.serialize = function (routerState) { };
196
+ }
197
+ /**
198
+ * @record
199
+ */
200
+ function SerializedRouterStateSnapshot() { }
201
+ if (false) {
202
+ /** @type {?} */
203
+ SerializedRouterStateSnapshot.prototype.root;
204
+ /** @type {?} */
205
+ SerializedRouterStateSnapshot.prototype.url;
206
+ }
207
+ class DefaultRouterStateSerializer {
208
+ /**
209
+ * @param {?} routerState
210
+ * @return {?}
211
+ */
212
+ serialize(routerState) {
213
+ return {
214
+ root: this.serializeRoute(routerState.root),
215
+ url: routerState.url
216
+ };
217
+ }
218
+ /**
219
+ * @private
220
+ * @param {?} route
221
+ * @return {?}
222
+ */
223
+ serializeRoute(route) {
224
+ /** @type {?} */
225
+ const children = route.children.map((/**
226
+ * @param {?} c
227
+ * @return {?}
228
+ */
229
+ c => this.serializeRoute(c)));
230
+ return {
231
+ url: route.url,
232
+ params: route.params,
233
+ queryParams: route.queryParams,
234
+ fragment: route.fragment,
235
+ data: route.data,
236
+ outlet: route.outlet,
237
+ component: null,
238
+ routeConfig: null,
239
+ root: (/** @type {?} */ (null)),
240
+ parent: null,
241
+ firstChild: children[0],
242
+ children: children,
243
+ pathFromRoot: (/** @type {?} */ (null)),
244
+ paramMap: route.paramMap,
245
+ queryParamMap: route.queryParamMap,
246
+ toString: route.toString
247
+ };
248
+ }
252
249
  }
253
250
 
254
- var RouterState_1;
255
- /**
256
- * @record
257
- * @template T
258
- */
259
- function RouterStateModel() { }
260
- if (false) {
261
- /** @type {?|undefined} */
262
- RouterStateModel.prototype.state;
263
- /** @type {?|undefined} */
264
- RouterStateModel.prototype.navigationId;
265
- /** @type {?} */
266
- RouterStateModel.prototype.trigger;
267
- }
268
- let RouterState = RouterState_1 = class RouterState {
269
- /**
270
- * @param {?} _store
271
- * @param {?} _router
272
- * @param {?} _serializer
273
- * @param {?} _ngZone
274
- * @param {?} _urlSerializer
275
- * @param {?} _locationStrategy
276
- * @param {?} _location
277
- */
278
- constructor(_store, _router, _serializer, _ngZone, _urlSerializer, _locationStrategy, _location) {
279
- this._store = _store;
280
- this._router = _router;
281
- this._serializer = _serializer;
282
- this._ngZone = _ngZone;
283
- this._urlSerializer = _urlSerializer;
284
- this._locationStrategy = _locationStrategy;
285
- this._location = _location;
286
- /**
287
- * Determines how navigation was performed by the `RouterState` itself
288
- * or outside via `new Navigate(...)`
289
- */
290
- this._trigger = 'none';
291
- /**
292
- * That's the serialized state from the `Router` class
293
- */
294
- this._routerState = null;
295
- /**
296
- * That's the value of the `RouterState` state
297
- */
298
- this._storeState = null;
299
- this._lastRoutesRecognized = (/** @type {?} */ (null));
300
- this._subscription = new Subscription();
301
- this.setUpStoreListener();
302
- this.setUpRouterEventsListener();
303
- this.checkInitialNavigationOnce();
304
- }
305
- /**
306
- * @template T
307
- * @param {?} state
308
- * @return {?}
309
- */
310
- static state(state) {
311
- return state && state.state;
312
- }
313
- /**
314
- * @param {?} state
315
- * @return {?}
316
- */
317
- static url(state) {
318
- return state && state.state && state.state.url;
319
- }
320
- /**
321
- * @return {?}
322
- */
323
- ngOnDestroy() {
324
- this._subscription.unsubscribe();
325
- }
326
- /**
327
- * @param {?} _
328
- * @param {?} action
329
- * @return {?}
330
- */
331
- navigate(_, action) {
332
- return this._ngZone.run((/**
333
- * @return {?}
334
- */
335
- () => this._router.navigate(action.path, Object.assign({ queryParams: action.queryParams }, action.extras))));
336
- }
337
- /**
338
- * @param {?} ctx
339
- * @param {?} action
340
- * @return {?}
341
- */
342
- angularRouterAction(ctx, action) {
343
- ctx.setState(Object.assign({}, ctx.getState(), { trigger: action.trigger, state: action.routerState, navigationId: action.event.id }));
344
- }
345
- /**
346
- * @private
347
- * @return {?}
348
- */
349
- setUpStoreListener() {
350
- /** @type {?} */
351
- const subscription = this._store
352
- .select(RouterState_1)
353
- .subscribe((/**
354
- * @param {?} state
355
- * @return {?}
356
- */
357
- (state) => {
358
- this.navigateIfNeeded(state);
359
- }));
360
- this._subscription.add(subscription);
361
- }
362
- /**
363
- * @private
364
- * @return {?}
365
- */
366
- setUpRouterEventsListener() {
367
- /** @type {?} */
368
- const subscription = this._router.events.subscribe((/**
369
- * @param {?} event
370
- * @return {?}
371
- */
372
- event => {
373
- if (event instanceof NavigationStart) {
374
- this.navigationStart();
375
- }
376
- else if (event instanceof RoutesRecognized) {
377
- this._lastRoutesRecognized = event;
378
- }
379
- else if (event instanceof ResolveEnd) {
380
- this.dispatchRouterDataResolved(event);
381
- }
382
- else if (event instanceof NavigationCancel) {
383
- this.dispatchRouterCancel(event);
384
- this.reset();
385
- }
386
- else if (event instanceof NavigationError) {
387
- this.dispatchRouterError(event);
388
- this.reset();
389
- }
390
- else if (event instanceof NavigationEnd) {
391
- this.navigationEnd();
392
- this.reset();
393
- }
394
- }));
395
- this._subscription.add(subscription);
396
- }
397
- /**
398
- * @private
399
- * @return {?}
400
- */
401
- navigationStart() {
402
- this._routerState = this._serializer.serialize(this._router.routerState.snapshot);
403
- if (this._trigger !== 'none') {
404
- this._storeState = this._store.selectSnapshot(RouterState_1);
405
- }
406
- }
407
- /**
408
- * @private
409
- * @return {?}
410
- */
411
- navigationEnd() {
412
- if (this.shouldDispatchRouterNavigation()) {
413
- this.dispatchRouterNavigation();
414
- }
415
- }
416
- /**
417
- * @private
418
- * @return {?}
419
- */
420
- shouldDispatchRouterNavigation() {
421
- if (!this._storeState)
422
- return true;
423
- return this._trigger !== 'store';
424
- }
425
- /**
426
- * @private
427
- * @param {?} state
428
- * @return {?}
429
- */
430
- navigateIfNeeded(state) {
431
- /** @type {?} */
432
- const canSkipNavigation = !this._storeState ||
433
- !this._storeState.state ||
434
- !state ||
435
- state.trigger === 'router' ||
436
- this._router.url === this._storeState.state.url;
437
- if (canSkipNavigation) {
438
- return;
439
- }
440
- this._trigger = 'store';
441
- this._ngZone.run((/**
442
- * @return {?}
443
- */
444
- () => {
445
- this._router.navigateByUrl((/** @type {?} */ ((/** @type {?} */ (this._storeState)).state)).url);
446
- }));
447
- }
448
- /**
449
- * @private
450
- * @return {?}
451
- */
452
- dispatchRouterNavigation() {
453
- /** @type {?} */
454
- const nextRouterState = this._serializer.serialize(this._lastRoutesRecognized.state);
455
- this.dispatchRouterAction(new RouterNavigation(nextRouterState, new RoutesRecognized(this._lastRoutesRecognized.id, this._lastRoutesRecognized.url, this._lastRoutesRecognized.urlAfterRedirects, nextRouterState), this._trigger));
456
- }
457
- /**
458
- * @private
459
- * @param {?} event
460
- * @return {?}
461
- */
462
- dispatchRouterCancel(event) {
463
- this.dispatchRouterAction(new RouterCancel((/** @type {?} */ (this._routerState)), this._storeState, event, this._trigger));
464
- }
465
- /**
466
- * @private
467
- * @param {?} event
468
- * @return {?}
469
- */
470
- dispatchRouterError(event) {
471
- this.dispatchRouterAction(new RouterError((/** @type {?} */ (this._routerState)), this._storeState, new NavigationError(event.id, event.url, `${event}`), this._trigger));
472
- }
473
- /**
474
- * @private
475
- * @template T
476
- * @param {?} action
477
- * @return {?}
478
- */
479
- dispatchRouterAction(action) {
480
- this._trigger = 'router';
481
- try {
482
- this._store.dispatch(action);
483
- }
484
- finally {
485
- this._trigger = 'none';
486
- }
487
- }
488
- /**
489
- * @private
490
- * @param {?} event
491
- * @return {?}
492
- */
493
- dispatchRouterDataResolved(event) {
494
- /** @type {?} */
495
- const routerState = this._serializer.serialize(event.state);
496
- this.dispatchRouterAction(new RouterDataResolved(routerState, event, this._trigger));
497
- }
498
- /**
499
- * @private
500
- * @return {?}
501
- */
502
- reset() {
503
- this._trigger = 'none';
504
- this._storeState = null;
505
- this._routerState = null;
506
- }
507
- /**
508
- * No sense to mess up the `setUpRouterEventsListener` method as we have
509
- * to perform this check only once and unsubscribe after the first event
510
- * is triggered
511
- * @private
512
- * @return {?}
513
- */
514
- checkInitialNavigationOnce() {
515
- // Caretaker note: we have still left the `typeof` condition in order to avoid
516
- // creating a breaking change for projects that still use the View Engine.
517
- if ((typeof ngDevMode === 'undefined' || ngDevMode) &&
518
- // Angular is running tests in development mode thus we can be sure that this method will be
519
- // skipped in tests.
520
- isAngularInTestMode()) {
521
- return;
522
- }
523
- /** @type {?} */
524
- const subscription = this._router.events
525
- .pipe(first((/**
526
- * @param {?} event
527
- * @return {?}
528
- */
529
- (event) => event instanceof RoutesRecognized)))
530
- .subscribe((/**
531
- * @param {?} __0
532
- * @return {?}
533
- */
534
- ({ url }) => {
535
- // `location.pathname` always equals manually entered URL in the address bar
536
- // e.g. `location.pathname === '/foo'`, but the `router` state has been initialized
537
- // with another URL (e.g. used in combination with `NgxsStoragePlugin`), thus the
538
- // `RouterNavigation` action will be dispatched and the user will be redirected to the
539
- // previously saved URL. We want to prevent such behavior, so we perform this check
540
- // `location.pathname` always equals manually entered URL in the address bar
541
- // e.g. `location.pathname === '/foo'`, but the `router` state has been initialized
542
- // with another URL (e.g. used in combination with `NgxsStoragePlugin`), thus the
543
- // `RouterNavigation` action will be dispatched and the user will be redirected to the
544
- // previously saved URL. We want to prevent such behavior, so we perform this check
545
- // `url` is a recognized URL by the Angular's router, while `currentUrl` is an actual URL
546
- // entered in the browser's address bar
547
- // `PathLocationStrategy.prototype.path()` returns a concatenation of
548
- // `PlatformLocation.pathname` and normalized `PlatformLocation.search`.
549
- // `Location.prototype.normalize` strips base href from the URL,
550
- // if `baseHref` (declared in angular.json) for example is `/en`
551
- // and the URL is `/test#anchor` - then `_locationStrategy.path(true)` will return `/en/test#anchor`,
552
- // but `/en/test#anchor` is not known to the Angular's router, so we have to strip `/en`
553
- // from the URL
554
- /** @type {?} */
555
- const currentUrl = this._location.normalize(this._locationStrategy.path(true));
556
- /** @type {?} */
557
- const currentUrlTree = this._urlSerializer.parse(currentUrl);
558
- // We need to serialize the URL because in that example `/test/?redirect=https://google.com/`
559
- // Angular will recognize it as `/test?redirect=https:%2F%2Fwww.google.com%2F`
560
- // so we have to run the `currentUrl` via the `UrlSerializer` that will encode characters
561
- /** @type {?} */
562
- const currentSerializedUrl = this._urlSerializer.serialize(currentUrlTree);
563
- // If URLs differ from each other - we've got to perform a redirect to the manually entered URL
564
- // in the address bar, as it must have a priority
565
- if (currentSerializedUrl !== url) {
566
- this._router.navigateByUrl(currentUrl);
567
- }
568
- }));
569
- this._subscription.add(subscription);
570
- }
571
- };
572
- RouterState.ctorParameters = () => [
573
- { type: Store },
574
- { type: Router },
575
- { type: RouterStateSerializer },
576
- { type: NgZone },
577
- { type: UrlSerializer },
578
- { type: LocationStrategy },
579
- { type: Location }
580
- ];
581
- RouterState.decorators = [
582
- { type: Injectable }
583
- ];
584
- /** @nocollapse */
585
- RouterState.ctorParameters = () => [
586
- { type: Store },
587
- { type: Router },
588
- { type: RouterStateSerializer },
589
- { type: NgZone },
590
- { type: UrlSerializer },
591
- { type: LocationStrategy },
592
- { type: Location }
593
- ];
594
- __decorate([
595
- Action(Navigate),
596
- __metadata("design:type", Function),
597
- __metadata("design:paramtypes", [Object, Navigate]),
598
- __metadata("design:returntype", void 0)
599
- ], RouterState.prototype, "navigate", null);
600
- __decorate([
601
- Action([RouterNavigation, RouterError, RouterCancel, RouterDataResolved]),
602
- __metadata("design:type", Function),
603
- __metadata("design:paramtypes", [Object, Object]),
604
- __metadata("design:returntype", void 0)
605
- ], RouterState.prototype, "angularRouterAction", null);
606
- __decorate([
607
- Selector(),
608
- __metadata("design:type", Function),
609
- __metadata("design:paramtypes", [Object]),
610
- __metadata("design:returntype", void 0)
611
- ], RouterState, "state", null);
612
- __decorate([
613
- Selector(),
614
- __metadata("design:type", Function),
615
- __metadata("design:paramtypes", [Object]),
616
- __metadata("design:returntype", Object)
617
- ], RouterState, "url", null);
618
- RouterState = RouterState_1 = __decorate([
619
- State({
620
- name: 'router',
621
- defaults: {
622
- state: undefined,
623
- navigationId: undefined,
624
- trigger: 'none'
625
- }
626
- }),
627
- __metadata("design:paramtypes", [Store,
628
- Router,
629
- RouterStateSerializer,
630
- NgZone,
631
- UrlSerializer,
632
- LocationStrategy,
633
- Location])
634
- ], RouterState);
635
- if (false) {
636
- /**
637
- * Determines how navigation was performed by the `RouterState` itself
638
- * or outside via `new Navigate(...)`
639
- * @type {?}
640
- * @private
641
- */
642
- RouterState.prototype._trigger;
643
- /**
644
- * That's the serialized state from the `Router` class
645
- * @type {?}
646
- * @private
647
- */
648
- RouterState.prototype._routerState;
649
- /**
650
- * That's the value of the `RouterState` state
651
- * @type {?}
652
- * @private
653
- */
654
- RouterState.prototype._storeState;
655
- /**
656
- * @type {?}
657
- * @private
658
- */
659
- RouterState.prototype._lastRoutesRecognized;
660
- /**
661
- * @type {?}
662
- * @private
663
- */
664
- RouterState.prototype._subscription;
665
- /**
666
- * @type {?}
667
- * @private
668
- */
669
- RouterState.prototype._store;
670
- /**
671
- * @type {?}
672
- * @private
673
- */
674
- RouterState.prototype._router;
675
- /**
676
- * @type {?}
677
- * @private
678
- */
679
- RouterState.prototype._serializer;
680
- /**
681
- * @type {?}
682
- * @private
683
- */
684
- RouterState.prototype._ngZone;
685
- /**
686
- * @type {?}
687
- * @private
688
- */
689
- RouterState.prototype._urlSerializer;
690
- /**
691
- * @type {?}
692
- * @private
693
- */
694
- RouterState.prototype._locationStrategy;
695
- /**
696
- * @type {?}
697
- * @private
698
- */
699
- RouterState.prototype._location;
251
+ var RouterState_1;
252
+ /**
253
+ * @record
254
+ * @template T
255
+ */
256
+ function RouterStateModel() { }
257
+ if (false) {
258
+ /** @type {?|undefined} */
259
+ RouterStateModel.prototype.state;
260
+ /** @type {?|undefined} */
261
+ RouterStateModel.prototype.navigationId;
262
+ /** @type {?} */
263
+ RouterStateModel.prototype.trigger;
264
+ }
265
+ let RouterState = RouterState_1 = class RouterState {
266
+ /**
267
+ * @param {?} _store
268
+ * @param {?} _router
269
+ * @param {?} _serializer
270
+ * @param {?} _ngZone
271
+ */
272
+ constructor(_store, _router, _serializer, _ngZone) {
273
+ this._store = _store;
274
+ this._router = _router;
275
+ this._serializer = _serializer;
276
+ this._ngZone = _ngZone;
277
+ /**
278
+ * Determines how navigation was performed by the `RouterState` itself
279
+ * or outside via `new Navigate(...)`
280
+ */
281
+ this._trigger = 'none';
282
+ /**
283
+ * That's the serialized state from the `Router` class
284
+ */
285
+ this._routerState = null;
286
+ /**
287
+ * That's the value of the `RouterState` state
288
+ */
289
+ this._storeState = null;
290
+ this._lastRoutesRecognized = (/** @type {?} */ (null));
291
+ this._subscription = new Subscription();
292
+ this.setUpStoreListener();
293
+ this.setUpRouterEventsListener();
294
+ }
295
+ /**
296
+ * @template T
297
+ * @param {?} state
298
+ * @return {?}
299
+ */
300
+ static state(state) {
301
+ return state && state.state;
302
+ }
303
+ /**
304
+ * @param {?} state
305
+ * @return {?}
306
+ */
307
+ static url(state) {
308
+ return state && state.state && state.state.url;
309
+ }
310
+ /**
311
+ * @return {?}
312
+ */
313
+ ngOnDestroy() {
314
+ this._subscription.unsubscribe();
315
+ }
316
+ /**
317
+ * @param {?} _
318
+ * @param {?} action
319
+ * @return {?}
320
+ */
321
+ navigate(_, action) {
322
+ return this._ngZone.run((/**
323
+ * @return {?}
324
+ */
325
+ () => this._router.navigate(action.path, Object.assign({ queryParams: action.queryParams }, action.extras))));
326
+ }
327
+ /**
328
+ * @param {?} ctx
329
+ * @param {?} action
330
+ * @return {?}
331
+ */
332
+ angularRouterAction(ctx, action) {
333
+ ctx.setState(Object.assign({}, ctx.getState(), { trigger: action.trigger, state: action.routerState, navigationId: action.event.id }));
334
+ }
335
+ /**
336
+ * @private
337
+ * @return {?}
338
+ */
339
+ setUpStoreListener() {
340
+ /** @type {?} */
341
+ const subscription = this._store
342
+ .select(RouterState_1)
343
+ .subscribe((/**
344
+ * @param {?} state
345
+ * @return {?}
346
+ */
347
+ (state) => {
348
+ this.navigateIfNeeded(state);
349
+ }));
350
+ this._subscription.add(subscription);
351
+ }
352
+ /**
353
+ * @private
354
+ * @return {?}
355
+ */
356
+ setUpRouterEventsListener() {
357
+ /** @type {?} */
358
+ const subscription = this._router.events.subscribe((/**
359
+ * @param {?} event
360
+ * @return {?}
361
+ */
362
+ event => {
363
+ if (event instanceof NavigationStart) {
364
+ this.navigationStart();
365
+ }
366
+ else if (event instanceof RoutesRecognized) {
367
+ this._lastRoutesRecognized = event;
368
+ }
369
+ else if (event instanceof ResolveEnd) {
370
+ this.dispatchRouterDataResolved(event);
371
+ }
372
+ else if (event instanceof NavigationCancel) {
373
+ this.dispatchRouterCancel(event);
374
+ this.reset();
375
+ }
376
+ else if (event instanceof NavigationError) {
377
+ this.dispatchRouterError(event);
378
+ this.reset();
379
+ }
380
+ else if (event instanceof NavigationEnd) {
381
+ this.navigationEnd();
382
+ this.reset();
383
+ }
384
+ }));
385
+ this._subscription.add(subscription);
386
+ }
387
+ /**
388
+ * @private
389
+ * @return {?}
390
+ */
391
+ navigationStart() {
392
+ this._routerState = this._serializer.serialize(this._router.routerState.snapshot);
393
+ if (this._trigger !== 'none') {
394
+ this._storeState = this._store.selectSnapshot(RouterState_1);
395
+ }
396
+ }
397
+ /**
398
+ * @private
399
+ * @return {?}
400
+ */
401
+ navigationEnd() {
402
+ if (this.shouldDispatchRouterNavigation()) {
403
+ this.dispatchRouterNavigation();
404
+ }
405
+ }
406
+ /**
407
+ * @private
408
+ * @return {?}
409
+ */
410
+ shouldDispatchRouterNavigation() {
411
+ if (!this._storeState)
412
+ return true;
413
+ return this._trigger !== 'store';
414
+ }
415
+ /**
416
+ * @private
417
+ * @param {?} state
418
+ * @return {?}
419
+ */
420
+ navigateIfNeeded(state) {
421
+ if (state && state.trigger === 'devtools') {
422
+ this._storeState = this._store.selectSnapshot(RouterState_1);
423
+ }
424
+ /** @type {?} */
425
+ const canSkipNavigation = !this._storeState ||
426
+ !this._storeState.state ||
427
+ !state ||
428
+ state.trigger === 'router' ||
429
+ this._router.url === this._storeState.state.url;
430
+ if (canSkipNavigation) {
431
+ return;
432
+ }
433
+ this._trigger = 'store';
434
+ this._ngZone.run((/**
435
+ * @return {?}
436
+ */
437
+ () => {
438
+ this._router.navigateByUrl((/** @type {?} */ ((/** @type {?} */ (this._storeState)).state)).url);
439
+ }));
440
+ }
441
+ /**
442
+ * @private
443
+ * @return {?}
444
+ */
445
+ dispatchRouterNavigation() {
446
+ /** @type {?} */
447
+ const nextRouterState = this._serializer.serialize(this._lastRoutesRecognized.state);
448
+ this.dispatchRouterAction(new RouterNavigation(nextRouterState, new RoutesRecognized(this._lastRoutesRecognized.id, this._lastRoutesRecognized.url, this._lastRoutesRecognized.urlAfterRedirects, nextRouterState), this._trigger));
449
+ }
450
+ /**
451
+ * @private
452
+ * @param {?} event
453
+ * @return {?}
454
+ */
455
+ dispatchRouterCancel(event) {
456
+ this.dispatchRouterAction(new RouterCancel((/** @type {?} */ (this._routerState)), this._storeState, event, this._trigger));
457
+ }
458
+ /**
459
+ * @private
460
+ * @param {?} event
461
+ * @return {?}
462
+ */
463
+ dispatchRouterError(event) {
464
+ this.dispatchRouterAction(new RouterError((/** @type {?} */ (this._routerState)), this._storeState, new NavigationError(event.id, event.url, `${event}`), this._trigger));
465
+ }
466
+ /**
467
+ * @private
468
+ * @template T
469
+ * @param {?} action
470
+ * @return {?}
471
+ */
472
+ dispatchRouterAction(action) {
473
+ this._trigger = 'router';
474
+ try {
475
+ this._store.dispatch(action);
476
+ }
477
+ finally {
478
+ this._trigger = 'none';
479
+ }
480
+ }
481
+ /**
482
+ * @private
483
+ * @param {?} event
484
+ * @return {?}
485
+ */
486
+ dispatchRouterDataResolved(event) {
487
+ /** @type {?} */
488
+ const routerState = this._serializer.serialize(event.state);
489
+ this.dispatchRouterAction(new RouterDataResolved(routerState, event, this._trigger));
490
+ }
491
+ /**
492
+ * @private
493
+ * @return {?}
494
+ */
495
+ reset() {
496
+ this._trigger = 'none';
497
+ this._storeState = null;
498
+ this._routerState = null;
499
+ }
500
+ };
501
+ RouterState.ctorParameters = () => [
502
+ { type: Store },
503
+ { type: Router },
504
+ { type: RouterStateSerializer },
505
+ { type: NgZone }
506
+ ];
507
+ RouterState.decorators = [
508
+ { type: Injectable }
509
+ ];
510
+ /** @nocollapse */
511
+ RouterState.ctorParameters = () => [
512
+ { type: Store },
513
+ { type: Router },
514
+ { type: RouterStateSerializer },
515
+ { type: NgZone }
516
+ ];
517
+ __decorate([
518
+ Action(Navigate),
519
+ __metadata("design:type", Function),
520
+ __metadata("design:paramtypes", [Object, Navigate]),
521
+ __metadata("design:returntype", void 0)
522
+ ], RouterState.prototype, "navigate", null);
523
+ __decorate([
524
+ Action([RouterNavigation, RouterError, RouterCancel, RouterDataResolved]),
525
+ __metadata("design:type", Function),
526
+ __metadata("design:paramtypes", [Object, Object]),
527
+ __metadata("design:returntype", void 0)
528
+ ], RouterState.prototype, "angularRouterAction", null);
529
+ __decorate([
530
+ Selector(),
531
+ __metadata("design:type", Function),
532
+ __metadata("design:paramtypes", [Object]),
533
+ __metadata("design:returntype", void 0)
534
+ ], RouterState, "state", null);
535
+ __decorate([
536
+ Selector(),
537
+ __metadata("design:type", Function),
538
+ __metadata("design:paramtypes", [Object]),
539
+ __metadata("design:returntype", Object)
540
+ ], RouterState, "url", null);
541
+ RouterState = RouterState_1 = __decorate([
542
+ State({
543
+ name: 'router',
544
+ defaults: {
545
+ state: undefined,
546
+ navigationId: undefined,
547
+ trigger: 'none'
548
+ }
549
+ }),
550
+ __metadata("design:paramtypes", [Store,
551
+ Router,
552
+ RouterStateSerializer,
553
+ NgZone])
554
+ ], RouterState);
555
+ if (false) {
556
+ /**
557
+ * Determines how navigation was performed by the `RouterState` itself
558
+ * or outside via `new Navigate(...)`
559
+ * @type {?}
560
+ * @private
561
+ */
562
+ RouterState.prototype._trigger;
563
+ /**
564
+ * That's the serialized state from the `Router` class
565
+ * @type {?}
566
+ * @private
567
+ */
568
+ RouterState.prototype._routerState;
569
+ /**
570
+ * That's the value of the `RouterState` state
571
+ * @type {?}
572
+ * @private
573
+ */
574
+ RouterState.prototype._storeState;
575
+ /**
576
+ * @type {?}
577
+ * @private
578
+ */
579
+ RouterState.prototype._lastRoutesRecognized;
580
+ /**
581
+ * @type {?}
582
+ * @private
583
+ */
584
+ RouterState.prototype._subscription;
585
+ /**
586
+ * @type {?}
587
+ * @private
588
+ */
589
+ RouterState.prototype._store;
590
+ /**
591
+ * @type {?}
592
+ * @private
593
+ */
594
+ RouterState.prototype._router;
595
+ /**
596
+ * @type {?}
597
+ * @private
598
+ */
599
+ RouterState.prototype._serializer;
600
+ /**
601
+ * @type {?}
602
+ * @private
603
+ */
604
+ RouterState.prototype._ngZone;
700
605
  }
701
606
 
702
- /**
703
- * @fileoverview added by tsickle
704
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
705
- */
706
- class NgxsRouterPluginModule {
707
- /**
708
- * @return {?}
709
- */
710
- static forRoot() {
711
- return {
712
- ngModule: NgxsRouterPluginModule,
713
- providers: [{ provide: RouterStateSerializer, useClass: DefaultRouterStateSerializer }]
714
- };
715
- }
716
- }
717
- NgxsRouterPluginModule.decorators = [
718
- { type: NgModule, args: [{
719
- imports: [NgxsModule.forFeature([RouterState])]
720
- },] }
607
+ /**
608
+ * @fileoverview added by tsickle
609
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
610
+ */
611
+ class NgxsRouterPluginModule {
612
+ /**
613
+ * @return {?}
614
+ */
615
+ static forRoot() {
616
+ return {
617
+ ngModule: NgxsRouterPluginModule,
618
+ providers: [{ provide: RouterStateSerializer, useClass: DefaultRouterStateSerializer }]
619
+ };
620
+ }
621
+ }
622
+ NgxsRouterPluginModule.decorators = [
623
+ { type: NgModule, args: [{
624
+ imports: [NgxsModule.forFeature([RouterState])]
625
+ },] }
721
626
  ];
722
627
 
723
- /**
724
- * @fileoverview added by tsickle
725
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
628
+ /**
629
+ * @fileoverview added by tsickle
630
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
726
631
  */
727
632
 
728
- /**
729
- * @fileoverview added by tsickle
730
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
633
+ /**
634
+ * @fileoverview added by tsickle
635
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
731
636
  */
732
637
 
733
- /**
734
- * @fileoverview added by tsickle
735
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
638
+ /**
639
+ * @fileoverview added by tsickle
640
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
736
641
  */
737
642
 
738
643
  export { DefaultRouterStateSerializer, Navigate, NgxsRouterPluginModule, RouterCancel, RouterDataResolved, RouterError, RouterNavigation, RouterState, RouterStateSerializer };