@tinkoff/router 0.1.64 → 0.1.65

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.
package/lib/index.es.js CHANGED
@@ -668,9 +668,11 @@ class RouteTree {
668
668
 
669
669
  class Router extends AbstractRouter {
670
670
  constructor(options) {
671
+ var _a;
671
672
  super(options);
672
673
  this.blocked = false;
673
674
  this.tree = new RouteTree(options.routes);
675
+ this.defaultRedirectCode = (_a = options.defaultRedirectCode) !== null && _a !== void 0 ? _a : 308;
674
676
  this.history = new ServerHistory();
675
677
  }
676
678
  async dehydrate() {
@@ -713,13 +715,13 @@ class Router extends AbstractRouter {
713
715
  normalizePathname(pathname) {
714
716
  const normalized = super.normalizePathname(pathname);
715
717
  if (normalized !== pathname) {
716
- this.redirectCode = 308;
718
+ this.redirectCode = this.defaultRedirectCode;
717
719
  }
718
720
  return normalized;
719
721
  }
720
722
  resolveUrl(options) {
721
723
  if (options.url && isInvalidUrl(options.url)) {
722
- this.redirectCode = 308;
724
+ this.redirectCode = this.defaultRedirectCode;
723
725
  }
724
726
  return super.resolveUrl(options);
725
727
  }
package/lib/index.js CHANGED
@@ -684,9 +684,11 @@ class RouteTree {
684
684
 
685
685
  class Router extends AbstractRouter {
686
686
  constructor(options) {
687
+ var _a;
687
688
  super(options);
688
689
  this.blocked = false;
689
690
  this.tree = new RouteTree(options.routes);
691
+ this.defaultRedirectCode = (_a = options.defaultRedirectCode) !== null && _a !== void 0 ? _a : 308;
690
692
  this.history = new ServerHistory();
691
693
  }
692
694
  async dehydrate() {
@@ -729,13 +731,13 @@ class Router extends AbstractRouter {
729
731
  normalizePathname(pathname) {
730
732
  const normalized = super.normalizePathname(pathname);
731
733
  if (normalized !== pathname) {
732
- this.redirectCode = 308;
734
+ this.redirectCode = this.defaultRedirectCode;
733
735
  }
734
736
  return normalized;
735
737
  }
736
738
  resolveUrl(options) {
737
739
  if (options.url && url.isInvalidUrl(options.url)) {
738
- this.redirectCode = 308;
740
+ this.redirectCode = this.defaultRedirectCode;
739
741
  }
740
742
  return super.resolveUrl(options);
741
743
  }
@@ -16,6 +16,7 @@ export interface Options {
16
16
  afterUpdateCurrent?: NavigationHook[];
17
17
  guards?: NavigationGuard[];
18
18
  onChange?: NavigationSyncHook[];
19
+ defaultRedirectCode?: number;
19
20
  }
20
21
  interface InternalOptions {
21
22
  history?: boolean;
@@ -1,14 +1,11 @@
1
1
  import type { Options } from './abstract';
2
2
  import { AbstractRouter } from './abstract';
3
- import type { Navigation, NavigateOptions, HookName, NavigationHook } from '../types';
3
+ import type { Navigation, NavigateOptions, HookName } from '../types';
4
4
  export declare class Router extends AbstractRouter {
5
+ protected defaultRedirectCode: number;
5
6
  protected blocked: boolean;
6
7
  protected redirectCode?: number;
7
- constructor(options: Options & {
8
- onRedirect: (navigation: Navigation) => Promise<void>;
9
- onNotFound: NavigationHook;
10
- onBlock: NavigationHook;
11
- });
8
+ constructor(options: Options);
12
9
  protected onRedirect: (navigation: Navigation) => Promise<void>;
13
10
  dehydrate(): Promise<Navigation>;
14
11
  protected run(navigation: Navigation): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinkoff/router",
3
- "version": "0.1.64",
3
+ "version": "0.1.65",
4
4
  "description": "router",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",