@breautek/router 4.1.3 → 5.0.0-beta.0
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/dist/router.js +7 -84
- package/dist/src/IOnNoRoute.d.ts +2 -1
- package/dist/src/Route.d.ts +3 -1
- package/dist/src/RouteMatcher.d.ts +3 -2
- package/eslint.config.js +14 -0
- package/package.json +28 -24
- package/pnpm-workspace.yaml +7 -0
- package/src/HashStrategy.ts +1 -1
- package/src/IOnNoRoute.ts +2 -1
- package/src/Route.tsx +12 -13
- package/src/RouteMatcher.ts +5 -5
- package/src/Router.tsx +12 -10
- package/src/TransitionSlide.ts +1 -1
- package/src/URLParser.ts +3 -3
- package/src/URLStrategy.ts +1 -1
- package/src/View.tsx +2 -0
package/dist/router.js
CHANGED
|
@@ -537,6 +537,8 @@ class Router extends React__namespace.Component {
|
|
|
537
537
|
this.$incomingRoute = null;
|
|
538
538
|
this.$exitingRoute = null;
|
|
539
539
|
this.setState({ shouldTransition: false });
|
|
540
|
+
}).catch((error) => {
|
|
541
|
+
console.error(error);
|
|
540
542
|
});
|
|
541
543
|
}
|
|
542
544
|
}
|
|
@@ -739,9 +741,8 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
739
741
|
};
|
|
740
742
|
|
|
741
743
|
function insertStyle(css) {
|
|
742
|
-
if (typeof window === 'undefined')
|
|
744
|
+
if (typeof window === 'undefined')
|
|
743
745
|
return;
|
|
744
|
-
}
|
|
745
746
|
const style = document.createElement('style');
|
|
746
747
|
style.setAttribute('type', 'text/css');
|
|
747
748
|
style.innerHTML = css;
|
|
@@ -777,6 +778,8 @@ class View extends React__namespace.Component {
|
|
|
777
778
|
componentDidMount() {
|
|
778
779
|
this.getTitle().then((title) => {
|
|
779
780
|
this.props.router.setTitle(title);
|
|
781
|
+
}).catch((e) => {
|
|
782
|
+
console.error(e);
|
|
780
783
|
});
|
|
781
784
|
document.body.classList.add(this.$getViewBodyClass());
|
|
782
785
|
let stylesheet = this.getViewStylesheet();
|
|
@@ -864,7 +867,6 @@ class Route extends React__namespace.Component {
|
|
|
864
867
|
$getChildren(component) {
|
|
865
868
|
let children = null;
|
|
866
869
|
if (!component) {
|
|
867
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
868
870
|
component = this;
|
|
869
871
|
}
|
|
870
872
|
if (!component.props.children) {
|
|
@@ -1017,88 +1019,9 @@ class TransitionSlide extends TransitionStrategy {
|
|
|
1017
1019
|
}
|
|
1018
1020
|
}
|
|
1019
1021
|
|
|
1020
|
-
var
|
|
1021
|
-
var version = "4.1.3";
|
|
1022
|
-
var description = "An alternate react router.";
|
|
1023
|
-
var main = "dist/router.js";
|
|
1024
|
-
var types = "dist/src/api.d.ts";
|
|
1025
|
-
var type = "commonjs";
|
|
1026
|
-
var publishConfig = {
|
|
1027
|
-
registry: "https://registry.npmjs.org"
|
|
1028
|
-
};
|
|
1029
|
-
var scripts = {
|
|
1030
|
-
test: "jest",
|
|
1031
|
-
lint: "eslint --ext .ts,.tsx '?(src|spec)/**/*.?(ts|tsx)' --cache",
|
|
1032
|
-
build: "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
1033
|
-
"publish-beta": "npm publish --tag beta",
|
|
1034
|
-
prepublishOnly: "npm run build",
|
|
1035
|
-
version: "npm run-script build",
|
|
1036
|
-
postversion: "git push && git push --tags"
|
|
1037
|
-
};
|
|
1038
|
-
var repository = {
|
|
1039
|
-
type: "git",
|
|
1040
|
-
url: "https://github.com/breautek/router"
|
|
1041
|
-
};
|
|
1042
|
-
var keywords = [
|
|
1043
|
-
"react",
|
|
1044
|
-
"router",
|
|
1045
|
-
"page",
|
|
1046
|
-
"screen",
|
|
1047
|
-
"navigation"
|
|
1048
|
-
];
|
|
1049
|
-
var author = "norman@normanbreau.com";
|
|
1050
|
-
var license = "MIT";
|
|
1051
|
-
var homepage = "https://github.com/breautek/router";
|
|
1052
|
-
var peerDependencies = {
|
|
1053
|
-
react: "16.x || 17.x || 18.x",
|
|
1054
|
-
"react-dom": "16.x || 17.x || 18.x"
|
|
1055
|
-
};
|
|
1056
|
-
var devDependencies = {
|
|
1057
|
-
"@rollup/plugin-commonjs": "28.0.1",
|
|
1058
|
-
"@rollup/plugin-json": "6.1.0",
|
|
1059
|
-
"@rollup/plugin-node-resolve": "15.3.0",
|
|
1060
|
-
"@testing-library/jest-dom": "6.6.3",
|
|
1061
|
-
"@testing-library/react": "16.0.1",
|
|
1062
|
-
"@types/jest": "29.5.14",
|
|
1063
|
-
"@types/react": "18.3.12",
|
|
1064
|
-
"@types/react-dom": "18.3.1",
|
|
1065
|
-
"@typescript-eslint/eslint-plugin": "7.18.0",
|
|
1066
|
-
"@typescript-eslint/parser": "7.18.0",
|
|
1067
|
-
ajv: "8.17.1",
|
|
1068
|
-
eslint: "8.57.1",
|
|
1069
|
-
"eslint-plugin-react": "7.37.2",
|
|
1070
|
-
glob: "11.0.0",
|
|
1071
|
-
"ignore-styles": "5.0.1",
|
|
1072
|
-
jest: "29.7.0",
|
|
1073
|
-
"jest-environment-jsdom": "29.7.0",
|
|
1074
|
-
"node-sass": "9.0.0",
|
|
1075
|
-
react: "18.3.1",
|
|
1076
|
-
"react-dom": "18.3.1",
|
|
1077
|
-
rollup: "4.24.4",
|
|
1078
|
-
"rollup-plugin-progress": "1.1.2",
|
|
1079
|
-
"rollup-plugin-sass": "1.14.0",
|
|
1080
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
1081
|
-
"ts-jest": "29.2.5",
|
|
1082
|
-
"ts-node": "10.9.2",
|
|
1083
|
-
typescript: "5.5.4"
|
|
1084
|
-
};
|
|
1022
|
+
var version = "5.0.0-beta.0";
|
|
1085
1023
|
var packageInfo = {
|
|
1086
|
-
|
|
1087
|
-
version: version,
|
|
1088
|
-
description: description,
|
|
1089
|
-
main: main,
|
|
1090
|
-
types: types,
|
|
1091
|
-
type: type,
|
|
1092
|
-
publishConfig: publishConfig,
|
|
1093
|
-
scripts: scripts,
|
|
1094
|
-
repository: repository,
|
|
1095
|
-
keywords: keywords,
|
|
1096
|
-
author: author,
|
|
1097
|
-
license: license,
|
|
1098
|
-
homepage: homepage,
|
|
1099
|
-
peerDependencies: peerDependencies,
|
|
1100
|
-
devDependencies: devDependencies
|
|
1101
|
-
};
|
|
1024
|
+
version: version};
|
|
1102
1025
|
|
|
1103
1026
|
const VERSION = packageInfo.version;
|
|
1104
1027
|
|
package/dist/src/IOnNoRoute.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { IRouteProps } from 'Route';
|
|
2
3
|
export interface IOnNoRoute {
|
|
3
|
-
(indexRoute: React.ReactElement
|
|
4
|
+
(indexRoute: React.ReactElement<IRouteProps>, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps>;
|
|
4
5
|
}
|
package/dist/src/Route.d.ts
CHANGED
|
@@ -3,12 +3,14 @@ import { View } from './View';
|
|
|
3
3
|
import { RouteMatcher } from './RouteMatcher';
|
|
4
4
|
import { RouterStrategy } from './RouterStrategy';
|
|
5
5
|
import { TransitionStrategy } from './TransitionStrategy';
|
|
6
|
-
export interface IRouteProps<T> {
|
|
6
|
+
export interface IRouteProps<T extends IComponentProps = IComponentProps> {
|
|
7
7
|
url: string;
|
|
8
8
|
component: React.ComponentClass<any>;
|
|
9
9
|
index?: boolean;
|
|
10
10
|
entryTransition?: TransitionStrategy;
|
|
11
11
|
exitTransition?: TransitionStrategy;
|
|
12
|
+
children?: React.ReactElement<IRouteProps> | React.ReactElement<IRouteProps>[];
|
|
13
|
+
ref?: React.Ref<Route>;
|
|
12
14
|
/**
|
|
13
15
|
* @internal
|
|
14
16
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRouteProps } from './Route';
|
|
1
2
|
import { RouterStrategy } from './RouterStrategy';
|
|
2
3
|
/**
|
|
3
4
|
* Will be invoked when no routes are found. Default implementation is to simply return the `indexRoute`.
|
|
@@ -6,7 +7,7 @@ import { RouterStrategy } from './RouterStrategy';
|
|
|
6
7
|
* @returns {React.ReactElement} An `ReactElement` of a `Route`
|
|
7
8
|
*/
|
|
8
9
|
export interface IOnNoRouteFunction {
|
|
9
|
-
(indexRoute: React.ReactElement, routes:
|
|
10
|
+
(indexRoute: React.ReactElement, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps>;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
12
13
|
* This class is reponsible for determing which route to render
|
|
@@ -25,5 +26,5 @@ export declare class RouteMatcher {
|
|
|
25
26
|
* @param indexRoute
|
|
26
27
|
* @param onNoRoute
|
|
27
28
|
*/
|
|
28
|
-
match(url: string, children:
|
|
29
|
+
match(url: string, children: React.ReactElement<IRouteProps>[], base: string, indexRoute?: React.ReactElement<IRouteProps>, onNoRoute?: IOnNoRouteFunction): React.ReactElement<IRouteProps>;
|
|
29
30
|
}
|
package/eslint.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@breautek/router",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.0",
|
|
4
4
|
"description": "An alternate react router.",
|
|
5
5
|
"main": "dist/router.js",
|
|
6
6
|
"types": "dist/src/api.d.ts",
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"test": "jest",
|
|
13
|
-
"lint": "eslint
|
|
13
|
+
"lint": "eslint ./src ./spec",
|
|
14
|
+
"lint:fix": "eslint --fix ./src ./spec",
|
|
14
15
|
"build": "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
15
16
|
"publish-beta": "npm publish --tag beta",
|
|
16
17
|
"prepublishOnly": "npm run build",
|
|
@@ -32,36 +33,39 @@
|
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"homepage": "https://github.com/breautek/router",
|
|
34
35
|
"peerDependencies": {
|
|
35
|
-
"react": "16.x || 17.x || 18.x",
|
|
36
|
-
"react-dom": "16.x || 17.x || 18.x"
|
|
36
|
+
"react": "16.x || 17.x || 18.x || 19.x",
|
|
37
|
+
"react-dom": "16.x || 17.x || 18.x || 19.x"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
+
"@jest/types": "30.0.5",
|
|
41
|
+
"@rollup/plugin-commonjs": "28.0.6",
|
|
40
42
|
"@rollup/plugin-json": "6.1.0",
|
|
41
|
-
"@rollup/plugin-node-resolve": "
|
|
43
|
+
"@rollup/plugin-node-resolve": "16.0.1",
|
|
42
44
|
"@testing-library/jest-dom": "6.6.3",
|
|
43
|
-
"@testing-library/react": "16.0
|
|
44
|
-
"@
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/react
|
|
47
|
-
"@
|
|
48
|
-
"@typescript-eslint/parser": "7.18.0",
|
|
45
|
+
"@testing-library/react": "16.3.0",
|
|
46
|
+
"@totalpave/eslint-plugin": "7.0.14",
|
|
47
|
+
"@types/jest": "30.0.0",
|
|
48
|
+
"@types/react": "19.1.8",
|
|
49
|
+
"@types/react-dom": "19.1.6",
|
|
49
50
|
"ajv": "8.17.1",
|
|
50
|
-
"
|
|
51
|
-
"eslint-plugin-react": "7.37.2",
|
|
52
|
-
"glob": "11.0.0",
|
|
51
|
+
"glob": "11.0.3",
|
|
53
52
|
"ignore-styles": "5.0.1",
|
|
54
|
-
"jest": "
|
|
55
|
-
"jest-environment-jsdom": "
|
|
56
|
-
"
|
|
57
|
-
"react": "
|
|
58
|
-
"
|
|
59
|
-
"rollup": "4.24.4",
|
|
53
|
+
"jest": "30.0.5",
|
|
54
|
+
"jest-environment-jsdom": "30.0.5",
|
|
55
|
+
"react": "19.1.0",
|
|
56
|
+
"react-dom": "19.1.0",
|
|
57
|
+
"rollup": "4.45.1",
|
|
60
58
|
"rollup-plugin-progress": "1.1.2",
|
|
61
|
-
"rollup-plugin-sass": "1.
|
|
59
|
+
"rollup-plugin-sass": "1.15.3",
|
|
62
60
|
"rollup-plugin-typescript2": "0.36.0",
|
|
63
|
-
"
|
|
61
|
+
"sass": "1.89.2",
|
|
62
|
+
"ts-jest": "29.4.0",
|
|
64
63
|
"ts-node": "10.9.2",
|
|
65
|
-
"typescript": "5.
|
|
64
|
+
"typescript": "5.8.3"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@types/events": "3.0.3",
|
|
68
|
+
"events": "3.3.0",
|
|
69
|
+
"tslib": "2.8.1"
|
|
66
70
|
}
|
|
67
71
|
}
|
package/src/HashStrategy.ts
CHANGED
package/src/IOnNoRoute.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { IRouteProps } from 'Route';
|
|
3
4
|
|
|
4
5
|
export interface IOnNoRoute {
|
|
5
|
-
(indexRoute: React.ReactElement
|
|
6
|
+
(indexRoute: React.ReactElement<IRouteProps>, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps>;
|
|
6
7
|
}
|
package/src/Route.tsx
CHANGED
|
@@ -5,12 +5,15 @@ import { RouteMatcher } from './RouteMatcher';
|
|
|
5
5
|
import { RouterStrategy } from './RouterStrategy';
|
|
6
6
|
import { TransitionStrategy } from './TransitionStrategy';
|
|
7
7
|
|
|
8
|
-
export interface IRouteProps<T> {
|
|
8
|
+
export interface IRouteProps<T extends IComponentProps = IComponentProps> {
|
|
9
9
|
url: string;
|
|
10
10
|
component: React.ComponentClass<any>;
|
|
11
11
|
index?: boolean;
|
|
12
12
|
entryTransition?: TransitionStrategy;
|
|
13
13
|
exitTransition?: TransitionStrategy;
|
|
14
|
+
children?: React.ReactElement<IRouteProps> | React.ReactElement<IRouteProps>[];
|
|
15
|
+
|
|
16
|
+
ref?: React.Ref<Route>;
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* @internal
|
|
@@ -38,10 +41,7 @@ export interface IComponentProps {
|
|
|
38
41
|
[key: string]: any;
|
|
39
42
|
}
|
|
40
43
|
|
|
41
|
-
|
|
42
|
-
export interface IRouteState {
|
|
43
|
-
|
|
44
|
-
}
|
|
44
|
+
export interface IRouteState {}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* This class represents a route that renders a {@link View} component
|
|
@@ -62,7 +62,7 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
62
62
|
return this.$node;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
private $getComponentsToRender(component: React.ReactElement | React.Component): React.ReactNode {
|
|
65
|
+
private $getComponentsToRender(component: React.ReactElement<IRouteProps> | React.Component<IRouteProps>): React.ReactNode {
|
|
66
66
|
let url: string = component.props.url;
|
|
67
67
|
let base: string = component.props.base || '';
|
|
68
68
|
|
|
@@ -70,14 +70,14 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
70
70
|
let ViewComponent: React.ElementType = component.props.component;
|
|
71
71
|
let child: React.ReactNode;
|
|
72
72
|
|
|
73
|
-
let routeComponent = component.props.matcher.match(url, this.$getChildren(component), base);
|
|
73
|
+
let routeComponent: React.ReactElement<IRouteProps> = component.props.matcher.match(url, this.$getChildren(component), base);
|
|
74
74
|
if (routeComponent) {
|
|
75
75
|
child = this.$getComponentsToRender(routeComponent);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
return (
|
|
79
79
|
<ViewComponent
|
|
80
|
-
{...component.props.componentProps}
|
|
80
|
+
{...component.props.componentProps as any}
|
|
81
81
|
ref={(node: React.Component) => {
|
|
82
82
|
if (node) {
|
|
83
83
|
if (node instanceof View) {
|
|
@@ -97,11 +97,10 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
97
97
|
);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
private $getChildren(component: React.Component | React.ReactElement): React.ReactElement[] {
|
|
101
|
-
let children: React.ReactElement[] = null;
|
|
100
|
+
private $getChildren(component: React.Component<IRouteProps> | React.ReactElement<IRouteProps>): React.ReactElement<IRouteProps>[] {
|
|
101
|
+
let children: React.ReactElement<IRouteProps>[] = null;
|
|
102
102
|
|
|
103
103
|
if (!component) {
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
105
104
|
component = this;
|
|
106
105
|
}
|
|
107
106
|
|
|
@@ -110,10 +109,10 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
110
109
|
}
|
|
111
110
|
|
|
112
111
|
if (component.props.children instanceof Array) {
|
|
113
|
-
children = component.props.children as React.ReactElement[];
|
|
112
|
+
children = component.props.children as React.ReactElement<IRouteProps>[];
|
|
114
113
|
}
|
|
115
114
|
else {
|
|
116
|
-
children = [ component.props.children as React.ReactElement ];
|
|
115
|
+
children = [ component.props.children as React.ReactElement<IRouteProps> ];
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
return children;
|
package/src/RouteMatcher.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {RouterStrategy} from './RouterStrategy';
|
|
|
11
11
|
* @returns {React.ReactElement} An `ReactElement` of a `Route`
|
|
12
12
|
*/
|
|
13
13
|
export interface IOnNoRouteFunction {
|
|
14
|
-
(indexRoute: React.ReactElement, routes:
|
|
14
|
+
(indexRoute: React.ReactElement, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps>;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
/**
|
|
@@ -25,7 +25,7 @@ export class RouteMatcher {
|
|
|
25
25
|
this.$strategy = routerStrategy;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
private $defaultNoRouteFunction(indexRoute: React.ReactElement
|
|
28
|
+
private $defaultNoRouteFunction(indexRoute: React.ReactElement<IRouteProps>, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps> {
|
|
29
29
|
return indexRoute;
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -38,11 +38,11 @@ export class RouteMatcher {
|
|
|
38
38
|
* @param indexRoute
|
|
39
39
|
* @param onNoRoute
|
|
40
40
|
*/
|
|
41
|
-
public match(url: string, children:
|
|
42
|
-
let componentToRender: React.ReactElement = null;
|
|
41
|
+
public match(url: string, children: React.ReactElement<IRouteProps>[], base: string, indexRoute?: React.ReactElement<IRouteProps>, onNoRoute?: IOnNoRouteFunction): React.ReactElement<IRouteProps> {
|
|
42
|
+
let componentToRender: React.ReactElement<IRouteProps> = null;
|
|
43
43
|
let params: IURLParams = null;
|
|
44
44
|
for (let i: number = 0; i < children.length; i++) {
|
|
45
|
-
let route: React.ReactElement = children[i];
|
|
45
|
+
let route: React.ReactElement<IRouteProps> = children[i];
|
|
46
46
|
let shouldAllowPartialMatching: boolean = !!route.props.children;
|
|
47
47
|
let parser: URLParser = new URLParser(base + route.props.url, shouldAllowPartialMatching);
|
|
48
48
|
params = parser.parse(url);
|
package/src/Router.tsx
CHANGED
|
@@ -6,7 +6,7 @@ import {RouteMatcher} from './RouteMatcher';
|
|
|
6
6
|
import { RouterStrategy } from './RouterStrategy';
|
|
7
7
|
import { IRouterStrategyClass } from './IRouterStrategyClass';
|
|
8
8
|
import {IOnNoRoute} from './IOnNoRoute';
|
|
9
|
-
import { Route } from "./Route";
|
|
9
|
+
import { IRouteProps, Route } from "./Route";
|
|
10
10
|
|
|
11
11
|
export interface IRouterProps {
|
|
12
12
|
strategy?: IRouterStrategyClass;
|
|
@@ -115,7 +115,7 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
115
115
|
* @ignore
|
|
116
116
|
*/
|
|
117
117
|
public render(): React.ReactNode {
|
|
118
|
-
let currentRoute: React.ReactElement = this.$matcher.match(this.state.url || '/', this.$getChildren(), '', this.$getIndexRoute(), this.props.onNoRoute);
|
|
118
|
+
let currentRoute: React.ReactElement<IRouteProps> = this.$matcher.match(this.state.url || '/', this.$getChildren(), '', this.$getIndexRoute(), this.props.onNoRoute);
|
|
119
119
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
120
120
|
let Root: React.ElementType = null;
|
|
121
121
|
if (this.props.component) {
|
|
@@ -141,7 +141,7 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
// Incoming will always be safe to render, hence no defensive checks
|
|
144
|
-
let incoming: React.ReactElement = React.cloneElement(currentRoute, {
|
|
144
|
+
let incoming: React.ReactElement<IRouteProps> = React.cloneElement(currentRoute, {
|
|
145
145
|
ref : (route: Route) => {
|
|
146
146
|
this.$incomingRoute = route;
|
|
147
147
|
}
|
|
@@ -198,6 +198,8 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
198
198
|
this.$incomingRoute = null;
|
|
199
199
|
this.$exitingRoute = null;
|
|
200
200
|
this.setState({shouldTransition: false});
|
|
201
|
+
}).catch((error: Error) => {
|
|
202
|
+
console.error(error);
|
|
201
203
|
});
|
|
202
204
|
}
|
|
203
205
|
}
|
|
@@ -245,14 +247,14 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
245
247
|
/**
|
|
246
248
|
* Gets the potential routes
|
|
247
249
|
*/
|
|
248
|
-
private $getChildren(): React.ReactElement[] {
|
|
249
|
-
let children: React.ReactElement[] = null;
|
|
250
|
+
private $getChildren(): React.ReactElement<IRouteProps>[] {
|
|
251
|
+
let children: React.ReactElement<IRouteProps>[] = null;
|
|
250
252
|
|
|
251
253
|
if (this.props.children instanceof Array) {
|
|
252
|
-
children = this.props.children as React.ReactElement[];
|
|
254
|
+
children = this.props.children as React.ReactElement<IRouteProps>[];
|
|
253
255
|
}
|
|
254
256
|
else {
|
|
255
|
-
children = [ this.props.children as React.ReactElement ];
|
|
257
|
+
children = [ this.props.children as React.ReactElement<IRouteProps> ];
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
return children;
|
|
@@ -261,10 +263,10 @@ export class Router<TRouterProps extends IRouterProps = IRouterProps> extends Re
|
|
|
261
263
|
/**
|
|
262
264
|
* Finds the index route. Returns null if there are no indexed routes.
|
|
263
265
|
*/
|
|
264
|
-
private $getIndexRoute(): React.ReactElement {
|
|
265
|
-
let children: React.ReactElement[] = this.$getChildren();
|
|
266
|
+
private $getIndexRoute(): React.ReactElement<IRouteProps> {
|
|
267
|
+
let children: React.ReactElement<IRouteProps>[] = this.$getChildren();
|
|
266
268
|
for (let i: number = 0; i < children.length; i++) {
|
|
267
|
-
let child: React.ReactElement = children[i];
|
|
269
|
+
let child: React.ReactElement<IRouteProps> = children[i];
|
|
268
270
|
if (child.props.index) {
|
|
269
271
|
return child;
|
|
270
272
|
}
|
package/src/TransitionSlide.ts
CHANGED
|
@@ -61,7 +61,7 @@ export class TransitionSlide extends TransitionStrategy {
|
|
|
61
61
|
exitingNode.style.transition = transitionString;
|
|
62
62
|
|
|
63
63
|
//Add transition listener
|
|
64
|
-
let onTransitionEnd = () => {
|
|
64
|
+
let onTransitionEnd = (): void => {
|
|
65
65
|
//cleanup
|
|
66
66
|
incomingNode.removeEventListener('transitionend', onTransitionEnd);
|
|
67
67
|
|
package/src/URLParser.ts
CHANGED
|
@@ -30,8 +30,8 @@ export class URLParser {
|
|
|
30
30
|
*/
|
|
31
31
|
public parse(url: string): IURLParams {
|
|
32
32
|
url = this.$stripURL(url);
|
|
33
|
-
let parts:
|
|
34
|
-
let patternParts:
|
|
33
|
+
let parts: string[] = this.$getParts(url);
|
|
34
|
+
let patternParts: string[] = this.$getParts(this.$pattern);
|
|
35
35
|
|
|
36
36
|
if ((!this.$allowPartialMatch && parts.length !== patternParts.length) || url === '') {
|
|
37
37
|
return null;
|
|
@@ -84,7 +84,7 @@ export class URLParser {
|
|
|
84
84
|
* @private
|
|
85
85
|
* @param {string} url URL to split
|
|
86
86
|
*/
|
|
87
|
-
private $getParts(url: string):
|
|
87
|
+
private $getParts(url: string): string[] {
|
|
88
88
|
url = this.$stripURL(url);
|
|
89
89
|
return url.split('/');
|
|
90
90
|
}
|
package/src/URLStrategy.ts
CHANGED
package/src/View.tsx
CHANGED
|
@@ -44,6 +44,8 @@ export abstract class View<TPageProps extends IViewProps = IViewProps> extends R
|
|
|
44
44
|
public componentDidMount(): void {
|
|
45
45
|
this.getTitle().then((title: string) => {
|
|
46
46
|
this.props.router.setTitle(title);
|
|
47
|
+
}).catch((e) => {
|
|
48
|
+
console.error(e);
|
|
47
49
|
});
|
|
48
50
|
|
|
49
51
|
document.body.classList.add(this.$getViewBodyClass());
|