@tinkoff/router 0.1.77 → 0.1.78

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.
@@ -221,17 +221,20 @@ class AbstractRouter {
221
221
  await this.runHooks('afterUpdateCurrent', navigation);
222
222
  }
223
223
  async navigate(navigateOptions) {
224
- return this.internalNavigate(typeof navigateOptions === 'string' ? { url: navigateOptions } : navigateOptions, {});
224
+ return this.internalNavigate(makeNavigateOptions(navigateOptions), {});
225
225
  }
226
- async internalNavigate(navigateOptions, { history }) {
226
+ async internalNavigate(navigateOptions, { history, redirect }) {
227
227
  var _a;
228
228
  const { url, replace, params, navigateState, code } = navigateOptions;
229
- const prevNavigation = (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
229
+ const prevNavigation = redirect
230
+ ? this.lastNavigation
231
+ : (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
230
232
  if (!url && !prevNavigation) {
231
233
  throw new Error('Navigate url should be specified and cannot be omitted for first navigation');
232
234
  }
233
235
  const resolvedUrl = this.resolveUrl(navigateOptions);
234
236
  const { to: from, url: fromUrl } = prevNavigation !== null && prevNavigation !== void 0 ? prevNavigation : {};
237
+ const redirectFrom = redirect ? this.currentNavigation.to : undefined;
235
238
  let navigation = {
236
239
  type: 'navigate',
237
240
  from,
@@ -241,6 +244,8 @@ class AbstractRouter {
241
244
  history,
242
245
  navigateState,
243
246
  code,
247
+ redirect,
248
+ redirectFrom,
244
249
  };
245
250
  await this.runHooks('beforeResolve', navigation);
246
251
  const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
@@ -792,7 +797,12 @@ class ClientRouter extends AbstractRouter {
792
797
  }
793
798
  async redirect(navigation, target) {
794
799
  await super.redirect(navigation, target);
795
- return this.navigate({ ...target, replace: target.replace || navigation.replace });
800
+ return this.internalNavigate({
801
+ ...target,
802
+ replace: target.replace || navigation.replace,
803
+ }, {
804
+ redirect: true,
805
+ });
796
806
  }
797
807
  }
798
808
 
package/lib/index.es.js CHANGED
@@ -221,17 +221,20 @@ class AbstractRouter {
221
221
  await this.runHooks('afterUpdateCurrent', navigation);
222
222
  }
223
223
  async navigate(navigateOptions) {
224
- return this.internalNavigate(typeof navigateOptions === 'string' ? { url: navigateOptions } : navigateOptions, {});
224
+ return this.internalNavigate(makeNavigateOptions(navigateOptions), {});
225
225
  }
226
- async internalNavigate(navigateOptions, { history }) {
226
+ async internalNavigate(navigateOptions, { history, redirect }) {
227
227
  var _a;
228
228
  const { url, replace, params, navigateState, code } = navigateOptions;
229
- const prevNavigation = (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
229
+ const prevNavigation = redirect
230
+ ? this.lastNavigation
231
+ : (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
230
232
  if (!url && !prevNavigation) {
231
233
  throw new Error('Navigate url should be specified and cannot be omitted for first navigation');
232
234
  }
233
235
  const resolvedUrl = this.resolveUrl(navigateOptions);
234
236
  const { to: from, url: fromUrl } = prevNavigation !== null && prevNavigation !== void 0 ? prevNavigation : {};
237
+ const redirectFrom = redirect ? this.currentNavigation.to : undefined;
235
238
  let navigation = {
236
239
  type: 'navigate',
237
240
  from,
@@ -241,6 +244,8 @@ class AbstractRouter {
241
244
  history,
242
245
  navigateState,
243
246
  code,
247
+ redirect,
248
+ redirectFrom,
244
249
  };
245
250
  await this.runHooks('beforeResolve', navigation);
246
251
  const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
@@ -1022,7 +1027,12 @@ class ClientRouter extends AbstractRouter {
1022
1027
  }
1023
1028
  async redirect(navigation, target) {
1024
1029
  await super.redirect(navigation, target);
1025
- return this.navigate({ ...target, replace: target.replace || navigation.replace });
1030
+ return this.internalNavigate({
1031
+ ...target,
1032
+ replace: target.replace || navigation.replace,
1033
+ }, {
1034
+ redirect: true,
1035
+ });
1026
1036
  }
1027
1037
  }
1028
1038
 
package/lib/index.js CHANGED
@@ -236,17 +236,20 @@ class AbstractRouter {
236
236
  await this.runHooks('afterUpdateCurrent', navigation);
237
237
  }
238
238
  async navigate(navigateOptions) {
239
- return this.internalNavigate(typeof navigateOptions === 'string' ? { url: navigateOptions } : navigateOptions, {});
239
+ return this.internalNavigate(makeNavigateOptions(navigateOptions), {});
240
240
  }
241
- async internalNavigate(navigateOptions, { history }) {
241
+ async internalNavigate(navigateOptions, { history, redirect }) {
242
242
  var _a;
243
243
  const { url, replace, params, navigateState, code } = navigateOptions;
244
- const prevNavigation = (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
244
+ const prevNavigation = redirect
245
+ ? this.lastNavigation
246
+ : (_a = this.currentNavigation) !== null && _a !== void 0 ? _a : this.lastNavigation;
245
247
  if (!url && !prevNavigation) {
246
248
  throw new Error('Navigate url should be specified and cannot be omitted for first navigation');
247
249
  }
248
250
  const resolvedUrl = this.resolveUrl(navigateOptions);
249
251
  const { to: from, url: fromUrl } = prevNavigation !== null && prevNavigation !== void 0 ? prevNavigation : {};
252
+ const redirectFrom = redirect ? this.currentNavigation.to : undefined;
250
253
  let navigation = {
251
254
  type: 'navigate',
252
255
  from,
@@ -256,6 +259,8 @@ class AbstractRouter {
256
259
  history,
257
260
  navigateState,
258
261
  code,
262
+ redirect,
263
+ redirectFrom,
259
264
  };
260
265
  await this.runHooks('beforeResolve', navigation);
261
266
  const to = this.resolveRoute({ url: resolvedUrl, params, navigateState }, { wildcard: true });
@@ -1037,7 +1042,12 @@ class ClientRouter extends AbstractRouter {
1037
1042
  }
1038
1043
  async redirect(navigation, target) {
1039
1044
  await super.redirect(navigation, target);
1040
- return this.navigate({ ...target, replace: target.replace || navigation.replace });
1045
+ return this.internalNavigate({
1046
+ ...target,
1047
+ replace: target.replace || navigation.replace,
1048
+ }, {
1049
+ redirect: true,
1050
+ });
1041
1051
  }
1042
1052
  }
1043
1053
 
@@ -20,6 +20,7 @@ export interface Options {
20
20
  }
21
21
  interface InternalOptions {
22
22
  history?: boolean;
23
+ redirect?: boolean;
23
24
  }
24
25
  export declare abstract class AbstractRouter {
25
26
  protected started: boolean;
@@ -45,7 +46,7 @@ export declare abstract class AbstractRouter {
45
46
  protected internalUpdateCurrentRoute(updateRouteOptions: UpdateCurrentRouteOptions, { history }: InternalOptions): Promise<void>;
46
47
  protected runUpdateCurrentRoute(navigation: Navigation): Promise<void>;
47
48
  navigate(navigateOptions: NavigateOptions | string): Promise<void>;
48
- protected internalNavigate(navigateOptions: NavigateOptions, { history }: InternalOptions): Promise<void>;
49
+ protected internalNavigate(navigateOptions: NavigateOptions, { history, redirect }: InternalOptions): Promise<void>;
49
50
  protected runNavigate(navigation: Navigation): Promise<void>;
50
51
  protected run(navigation: Navigation): Promise<void>;
51
52
  resolve(resolveOptions: NavigateOptions | string, options?: Parameters<AbstractRouter['resolveRoute']>[1]): import("../types").NavigationRoute;
package/lib/types.d.ts CHANGED
@@ -40,6 +40,8 @@ export interface Navigation {
40
40
  history?: boolean;
41
41
  cancelled?: boolean;
42
42
  code?: number;
43
+ redirect?: boolean;
44
+ redirectFrom?: NavigationRoute;
43
45
  }
44
46
  export declare type NavigationGuard = (navigation: Navigation) => Promise<void | NavigateOptions | string | boolean>;
45
47
  export declare type NavigationHook = (navigation: Navigation) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkoff/router",
3
- "version": "0.1.77",
3
+ "version": "0.1.78",
4
4
  "description": "router",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",