@breautek/router 4.1.2 → 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 +18 -96
- package/dist/src/IOnNoRoute.d.ts +2 -1
- package/dist/src/Route.d.ts +12 -1
- package/dist/src/RouteMatcher.d.ts +3 -3
- package/dist/src/RouterStrategy.d.ts +0 -1
- package/dist/src/View.d.ts +1 -1
- package/eslint.config.js +14 -0
- package/package.json +30 -26
- package/pnpm-workspace.yaml +7 -0
- package/src/HashStrategy.ts +1 -1
- package/src/IOnNoRoute.ts +2 -1
- package/src/Route.tsx +23 -12
- 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 +3 -1
package/dist/router.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function ___$insertStyle(css) {
|
|
6
|
-
if (!css || typeof window === 'undefined') {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const style = document.createElement('style');
|
|
10
|
-
style.setAttribute('type', 'text/css');
|
|
11
|
-
style.innerHTML = css;
|
|
12
|
-
document.head.appendChild(style);
|
|
13
|
-
return css;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
3
|
var React = require('react');
|
|
17
4
|
var events = require('events');
|
|
18
5
|
|
|
@@ -550,6 +537,8 @@ class Router extends React__namespace.Component {
|
|
|
550
537
|
this.$incomingRoute = null;
|
|
551
538
|
this.$exitingRoute = null;
|
|
552
539
|
this.setState({ shouldTransition: false });
|
|
540
|
+
}).catch((error) => {
|
|
541
|
+
console.error(error);
|
|
553
542
|
});
|
|
554
543
|
}
|
|
555
544
|
}
|
|
@@ -733,7 +722,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
733
722
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
734
723
|
PERFORMANCE OF THIS SOFTWARE.
|
|
735
724
|
***************************************************************************** */
|
|
736
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
725
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
737
726
|
|
|
738
727
|
|
|
739
728
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
@@ -751,7 +740,17 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
751
740
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
752
741
|
};
|
|
753
742
|
|
|
754
|
-
|
|
743
|
+
function insertStyle(css) {
|
|
744
|
+
if (typeof window === 'undefined')
|
|
745
|
+
return;
|
|
746
|
+
const style = document.createElement('style');
|
|
747
|
+
style.setAttribute('type', 'text/css');
|
|
748
|
+
style.innerHTML = css;
|
|
749
|
+
document.head.appendChild(style);
|
|
750
|
+
return css;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
insertStyle(".View {\n position: static;\n top: 0px;\n left: 0px;\n width: 100%;\n height: 100%;\n z-index: 1;\n}");
|
|
755
754
|
|
|
756
755
|
class View extends React__namespace.Component {
|
|
757
756
|
/**
|
|
@@ -779,6 +778,8 @@ class View extends React__namespace.Component {
|
|
|
779
778
|
componentDidMount() {
|
|
780
779
|
this.getTitle().then((title) => {
|
|
781
780
|
this.props.router.setTitle(title);
|
|
781
|
+
}).catch((e) => {
|
|
782
|
+
console.error(e);
|
|
782
783
|
});
|
|
783
784
|
document.body.classList.add(this.$getViewBodyClass());
|
|
784
785
|
let stylesheet = this.getViewStylesheet();
|
|
@@ -1018,88 +1019,9 @@ class TransitionSlide extends TransitionStrategy {
|
|
|
1018
1019
|
}
|
|
1019
1020
|
}
|
|
1020
1021
|
|
|
1021
|
-
var
|
|
1022
|
-
var version = "4.1.2";
|
|
1023
|
-
var description = "An alternate react router.";
|
|
1024
|
-
var main = "dist/router.js";
|
|
1025
|
-
var types = "dist/src/api.d.ts";
|
|
1026
|
-
var type = "commonjs";
|
|
1027
|
-
var publishConfig = {
|
|
1028
|
-
registry: "https://registry.npmjs.org"
|
|
1029
|
-
};
|
|
1030
|
-
var scripts = {
|
|
1031
|
-
test: "jest",
|
|
1032
|
-
lint: "eslint --ext .ts,.tsx '?(src|spec)/**/*.?(ts|tsx)' --cache",
|
|
1033
|
-
build: "rollup -c rollup.config.js --bundleConfigAsCjs",
|
|
1034
|
-
"publish-beta": "npm publish --tag beta",
|
|
1035
|
-
prepublishOnly: "npm run build",
|
|
1036
|
-
version: "npm run-script build",
|
|
1037
|
-
postversion: "git push && git push --tags"
|
|
1038
|
-
};
|
|
1039
|
-
var repository = {
|
|
1040
|
-
type: "git",
|
|
1041
|
-
url: "https://github.com/breautek/router"
|
|
1042
|
-
};
|
|
1043
|
-
var keywords = [
|
|
1044
|
-
"react",
|
|
1045
|
-
"router",
|
|
1046
|
-
"page",
|
|
1047
|
-
"screen",
|
|
1048
|
-
"navigation"
|
|
1049
|
-
];
|
|
1050
|
-
var author = "norman@normanbreau.com";
|
|
1051
|
-
var license = "MIT";
|
|
1052
|
-
var homepage = "https://github.com/breautek/router";
|
|
1053
|
-
var peerDependencies = {
|
|
1054
|
-
react: "16.x || 17.x || 18.x",
|
|
1055
|
-
"react-dom": "16.x || 17.x || 18.x"
|
|
1056
|
-
};
|
|
1057
|
-
var devDependencies = {
|
|
1058
|
-
"@rollup/plugin-commonjs": "25.0.7",
|
|
1059
|
-
"@rollup/plugin-json": "6.1.0",
|
|
1060
|
-
"@rollup/plugin-node-resolve": "15.2.3",
|
|
1061
|
-
"@testing-library/jest-dom": "6.4.5",
|
|
1062
|
-
"@testing-library/react": "15.0.7",
|
|
1063
|
-
"@types/jest": "29.5.12",
|
|
1064
|
-
"@types/react": "18.3.2",
|
|
1065
|
-
"@types/react-dom": "18.3.0",
|
|
1066
|
-
"@typescript-eslint/eslint-plugin": "7.9.0",
|
|
1067
|
-
"@typescript-eslint/parser": "7.9.0",
|
|
1068
|
-
ajv: "8.13.0",
|
|
1069
|
-
eslint: "8.56.0",
|
|
1070
|
-
"eslint-plugin-react": "7.34.1",
|
|
1071
|
-
glob: "10.3.15",
|
|
1072
|
-
"ignore-styles": "5.0.1",
|
|
1073
|
-
jest: "29.7.0",
|
|
1074
|
-
"jest-environment-jsdom": "29.7.0",
|
|
1075
|
-
"node-sass": "9.0.0",
|
|
1076
|
-
react: "18.3.1",
|
|
1077
|
-
"react-dom": "18.3.1",
|
|
1078
|
-
rollup: "4.17.2",
|
|
1079
|
-
"rollup-plugin-progress": "1.1.2",
|
|
1080
|
-
"rollup-plugin-sass": "1.12.22",
|
|
1081
|
-
"rollup-plugin-typescript2": "0.36.0",
|
|
1082
|
-
"ts-jest": "29.1.2",
|
|
1083
|
-
"ts-node": "10.9.2",
|
|
1084
|
-
typescript: "5.4.5"
|
|
1085
|
-
};
|
|
1022
|
+
var version = "5.0.0-beta.0";
|
|
1086
1023
|
var packageInfo = {
|
|
1087
|
-
|
|
1088
|
-
version: version,
|
|
1089
|
-
description: description,
|
|
1090
|
-
main: main,
|
|
1091
|
-
types: types,
|
|
1092
|
-
type: type,
|
|
1093
|
-
publishConfig: publishConfig,
|
|
1094
|
-
scripts: scripts,
|
|
1095
|
-
repository: repository,
|
|
1096
|
-
keywords: keywords,
|
|
1097
|
-
author: author,
|
|
1098
|
-
license: license,
|
|
1099
|
-
homepage: homepage,
|
|
1100
|
-
peerDependencies: peerDependencies,
|
|
1101
|
-
devDependencies: devDependencies
|
|
1102
|
-
};
|
|
1024
|
+
version: version};
|
|
1103
1025
|
|
|
1104
1026
|
const VERSION = packageInfo.version;
|
|
1105
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,14 +3,25 @@ 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>;
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
12
17
|
base?: string;
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
13
21
|
componentProps?: T;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
14
25
|
matcher?: RouteMatcher;
|
|
15
26
|
}
|
|
16
27
|
export interface IComponentProps {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { IRouteProps } from './Route';
|
|
2
2
|
import { RouterStrategy } from './RouterStrategy';
|
|
3
3
|
/**
|
|
4
4
|
* Will be invoked when no routes are found. Default implementation is to simply return the `indexRoute`.
|
|
@@ -7,7 +7,7 @@ import { RouterStrategy } from './RouterStrategy';
|
|
|
7
7
|
* @returns {React.ReactElement} An `ReactElement` of a `Route`
|
|
8
8
|
*/
|
|
9
9
|
export interface IOnNoRouteFunction {
|
|
10
|
-
(indexRoute: React.ReactElement, routes:
|
|
10
|
+
(indexRoute: React.ReactElement, routes: React.ReactElement<IRouteProps>[]): React.ReactElement<IRouteProps>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* This class is reponsible for determing which route to render
|
|
@@ -26,5 +26,5 @@ export declare class RouteMatcher {
|
|
|
26
26
|
* @param indexRoute
|
|
27
27
|
* @param onNoRoute
|
|
28
28
|
*/
|
|
29
|
-
match(url: string, children:
|
|
29
|
+
match(url: string, children: React.ReactElement<IRouteProps>[], base: string, indexRoute?: React.ReactElement<IRouteProps>, onNoRoute?: IOnNoRouteFunction): React.ReactElement<IRouteProps>;
|
|
30
30
|
}
|
package/dist/src/View.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare abstract class View<TPageProps extends IViewProps = IViewProps> e
|
|
|
38
38
|
* Get the inline styles for this view.
|
|
39
39
|
* Use React style notation.
|
|
40
40
|
*/
|
|
41
|
-
getViewStyles():
|
|
41
|
+
getViewStyles(): React.CSSProperties;
|
|
42
42
|
protected abstract _renderView(): React.ReactNode;
|
|
43
43
|
render(): React.ReactNode;
|
|
44
44
|
}
|
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": "
|
|
42
|
-
"@testing-library/jest-dom": "6.
|
|
43
|
-
"@testing-library/react": "
|
|
44
|
-
"@
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/react
|
|
47
|
-
"@
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"eslint": "8.56.0",
|
|
51
|
-
"eslint-plugin-react": "7.34.1",
|
|
52
|
-
"glob": "10.3.15",
|
|
43
|
+
"@rollup/plugin-node-resolve": "16.0.1",
|
|
44
|
+
"@testing-library/jest-dom": "6.6.3",
|
|
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",
|
|
50
|
+
"ajv": "8.17.1",
|
|
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.17.2",
|
|
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,15 +5,29 @@ 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>[];
|
|
14
15
|
|
|
16
|
+
ref?: React.Ref<Route>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
15
21
|
base?: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
16
26
|
componentProps?: T;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/
|
|
17
31
|
matcher?: RouteMatcher;
|
|
18
32
|
}
|
|
19
33
|
|
|
@@ -27,10 +41,7 @@ export interface IComponentProps {
|
|
|
27
41
|
[key: string]: any;
|
|
28
42
|
}
|
|
29
43
|
|
|
30
|
-
|
|
31
|
-
export interface IRouteState {
|
|
32
|
-
|
|
33
|
-
}
|
|
44
|
+
export interface IRouteState {}
|
|
34
45
|
|
|
35
46
|
/**
|
|
36
47
|
* This class represents a route that renders a {@link View} component
|
|
@@ -51,7 +62,7 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
51
62
|
return this.$node;
|
|
52
63
|
}
|
|
53
64
|
|
|
54
|
-
private $getComponentsToRender(component: React.ReactElement | React.Component): React.ReactNode {
|
|
65
|
+
private $getComponentsToRender(component: React.ReactElement<IRouteProps> | React.Component<IRouteProps>): React.ReactNode {
|
|
55
66
|
let url: string = component.props.url;
|
|
56
67
|
let base: string = component.props.base || '';
|
|
57
68
|
|
|
@@ -59,14 +70,14 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
59
70
|
let ViewComponent: React.ElementType = component.props.component;
|
|
60
71
|
let child: React.ReactNode;
|
|
61
72
|
|
|
62
|
-
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);
|
|
63
74
|
if (routeComponent) {
|
|
64
75
|
child = this.$getComponentsToRender(routeComponent);
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
return (
|
|
68
79
|
<ViewComponent
|
|
69
|
-
{...component.props.componentProps}
|
|
80
|
+
{...component.props.componentProps as any}
|
|
70
81
|
ref={(node: React.Component) => {
|
|
71
82
|
if (node) {
|
|
72
83
|
if (node instanceof View) {
|
|
@@ -86,8 +97,8 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
86
97
|
);
|
|
87
98
|
}
|
|
88
99
|
|
|
89
|
-
private $getChildren(component: React.Component | React.ReactElement): React.ReactElement[] {
|
|
90
|
-
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;
|
|
91
102
|
|
|
92
103
|
if (!component) {
|
|
93
104
|
component = this;
|
|
@@ -98,10 +109,10 @@ export class Route<TComponentProps extends IComponentProps = IComponentProps, TR
|
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
if (component.props.children instanceof Array) {
|
|
101
|
-
children = component.props.children as React.ReactElement[];
|
|
112
|
+
children = component.props.children as React.ReactElement<IRouteProps>[];
|
|
102
113
|
}
|
|
103
114
|
else {
|
|
104
|
-
children = [ component.props.children as React.ReactElement ];
|
|
115
|
+
children = [ component.props.children as React.ReactElement<IRouteProps> ];
|
|
105
116
|
}
|
|
106
117
|
|
|
107
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());
|
|
@@ -87,7 +89,7 @@ export abstract class View<TPageProps extends IViewProps = IViewProps> extends R
|
|
|
87
89
|
* Get the inline styles for this view.
|
|
88
90
|
* Use React style notation.
|
|
89
91
|
*/
|
|
90
|
-
public getViewStyles():
|
|
92
|
+
public getViewStyles(): React.CSSProperties {
|
|
91
93
|
return {};
|
|
92
94
|
}
|
|
93
95
|
|