@breautek/router 3.0.1 → 4.0.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/CHANGELOG.legacy.md +206 -0
- package/CHANGELOG.md +11 -197
- package/dist/router.js +985 -1808
- package/dist/src/DefaultStrategy.d.ts +5 -5
- package/dist/src/HashStrategy.d.ts +28 -28
- package/dist/src/IOnNoRoute.d.ts +4 -4
- package/dist/src/IRouterStrategyClass.d.ts +8 -8
- package/dist/src/IViewStylesheet.d.ts +4 -4
- package/dist/src/Route.d.ts +33 -33
- package/dist/src/RouteMatcher.d.ts +30 -31
- package/dist/src/Router.d.ts +89 -85
- package/dist/src/RouterStrategy.d.ts +138 -117
- package/dist/src/TransitionSlide.d.ts +17 -17
- package/dist/src/TransitionStrategy.d.ts +21 -21
- package/dist/src/URLParser.d.ts +39 -39
- package/dist/src/URLStrategy.d.ts +32 -32
- package/dist/src/View.d.ts +48 -49
- package/dist/src/api.d.ts +13 -14
- package/package.json +30 -46
- package/src/HashStrategy.ts +1 -1
- package/src/RouteMatcher.ts +0 -2
- package/src/Router.tsx +5 -2
- package/src/RouterStrategy.ts +53 -0
- package/src/URLStrategy.ts +1 -0
- package/src/View.tsx +3 -3
- package/src/api.ts +0 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IRouterStrategyClass } from './IRouterStrategyClass';
|
|
2
|
-
/**
|
|
3
|
-
Alias for {@link HashStrategy}
|
|
4
|
-
*/
|
|
5
|
-
export declare let DefaultStrategy: IRouterStrategyClass;
|
|
1
|
+
import { IRouterStrategyClass } from './IRouterStrategyClass';
|
|
2
|
+
/**
|
|
3
|
+
Alias for {@link HashStrategy}
|
|
4
|
+
*/
|
|
5
|
+
export declare let DefaultStrategy: IRouterStrategyClass;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { RouterStrategy } from './RouterStrategy';
|
|
2
|
-
import { Router } from './Router';
|
|
3
|
-
/**
|
|
4
|
-
A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
|
|
5
|
-
URLs will have a starting point `/#/`, as a default base.
|
|
1
|
+
import { RouterStrategy } from './RouterStrategy';
|
|
2
|
+
import { Router } from './Router';
|
|
3
|
+
/**
|
|
4
|
+
A {@link RouterStrategy} that manages a history stack using inline pound symbols `#`.
|
|
5
|
+
URLs will have a starting point `/#/`, as a default base.
|
|
6
6
|
|
|
7
|
-
For example, if you [pushState("mylink")]{@link pushState}, the url
|
|
8
|
-
`/#/mylink` will be produced.
|
|
9
|
-
*/
|
|
10
|
-
export declare class HashStrategy extends RouterStrategy {
|
|
11
|
-
private $base;
|
|
12
|
-
private $stack;
|
|
13
|
-
private $position;
|
|
14
|
-
private $lastFiredLocation;
|
|
15
|
-
constructor(router: Router);
|
|
16
|
-
private $init;
|
|
17
|
-
getLocation(): string;
|
|
18
|
-
getLocationAt(position: number): string;
|
|
19
|
-
getHistoryLength(): number;
|
|
20
|
-
getScrollRestoration(): ScrollRestoration;
|
|
21
|
-
canGo(to: number): boolean;
|
|
22
|
-
peek(to: number): string;
|
|
23
|
-
go(to: number): void;
|
|
24
|
-
pushState(url: string, state?: Record<any, any>): void;
|
|
25
|
-
replaceState(url: string, state?: Record<any, any>): void;
|
|
26
|
-
clear(): void;
|
|
27
|
-
private $navigate;
|
|
28
|
-
protected _fireURLChange(url: string): void;
|
|
29
|
-
}
|
|
7
|
+
For example, if you [pushState("mylink")]{@link pushState}, the url
|
|
8
|
+
`/#/mylink` will be produced.
|
|
9
|
+
*/
|
|
10
|
+
export declare class HashStrategy extends RouterStrategy {
|
|
11
|
+
private $base;
|
|
12
|
+
private $stack;
|
|
13
|
+
private $position;
|
|
14
|
+
private $lastFiredLocation;
|
|
15
|
+
constructor(router: Router);
|
|
16
|
+
private $init;
|
|
17
|
+
getLocation(): string;
|
|
18
|
+
getLocationAt(position: number): string;
|
|
19
|
+
getHistoryLength(): number;
|
|
20
|
+
getScrollRestoration(): ScrollRestoration;
|
|
21
|
+
canGo(to: number): boolean;
|
|
22
|
+
peek(to: number): string;
|
|
23
|
+
go(to: number): void;
|
|
24
|
+
pushState(url: string, state?: Record<any, any>): void;
|
|
25
|
+
replaceState(url: string, state?: Record<any, any>): void;
|
|
26
|
+
clear(): void;
|
|
27
|
+
private $navigate;
|
|
28
|
+
protected _fireURLChange(url: string): void;
|
|
29
|
+
}
|
package/dist/src/IOnNoRoute.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export interface IOnNoRoute {
|
|
3
|
-
(indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
|
|
4
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface IOnNoRoute {
|
|
3
|
+
(indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
|
|
4
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { RouterStrategy } from './RouterStrategy';
|
|
2
|
-
import { Router } from './Router';
|
|
3
|
-
/**
|
|
4
|
-
* An interface to generically reference a {@link RouterStrategy} class
|
|
5
|
-
*/
|
|
6
|
-
export interface IRouterStrategyClass {
|
|
7
|
-
new (router: Router): RouterStrategy;
|
|
8
|
-
}
|
|
1
|
+
import { RouterStrategy } from './RouterStrategy';
|
|
2
|
+
import { Router } from './Router';
|
|
3
|
+
/**
|
|
4
|
+
* An interface to generically reference a {@link RouterStrategy} class
|
|
5
|
+
*/
|
|
6
|
+
export interface IRouterStrategyClass {
|
|
7
|
+
new (router: Router): RouterStrategy;
|
|
8
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export interface IViewStylesheet {
|
|
2
|
-
use: () => void;
|
|
3
|
-
unuse: () => void;
|
|
4
|
-
}
|
|
1
|
+
export interface IViewStylesheet {
|
|
2
|
+
use: () => void;
|
|
3
|
+
unuse: () => void;
|
|
4
|
+
}
|
package/dist/src/Route.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { View } from './View';
|
|
3
|
-
import { RouteMatcher } from './RouteMatcher';
|
|
4
|
-
import { RouterStrategy } from './RouterStrategy';
|
|
5
|
-
import { TransitionStrategy } from 'TransitionStrategy';
|
|
6
|
-
export interface IRouteProps<T> {
|
|
7
|
-
url: string;
|
|
8
|
-
component: React.ComponentClass<any>;
|
|
9
|
-
index?: boolean;
|
|
10
|
-
entryTransition?: TransitionStrategy;
|
|
11
|
-
exitTransition?: TransitionStrategy;
|
|
12
|
-
base?: string;
|
|
13
|
-
componentProps?: T;
|
|
14
|
-
matcher?: RouteMatcher;
|
|
15
|
-
}
|
|
16
|
-
export interface IComponentProps {
|
|
17
|
-
url: string;
|
|
18
|
-
router: RouterStrategy;
|
|
19
|
-
[key: string]: any;
|
|
20
|
-
}
|
|
21
|
-
export interface IRouteState {
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* This class represents a route that renders a {@link View} component
|
|
25
|
-
*/
|
|
26
|
-
export declare class Route<TComponentProps extends IComponentProps = IComponentProps, TRouteProps extends IRouteProps<TComponentProps> = IRouteProps<TComponentProps>, TRouteState extends IRouteState = IRouteState> extends React.Component<TRouteProps, TRouteState> {
|
|
27
|
-
private $node;
|
|
28
|
-
constructor(props: TRouteProps);
|
|
29
|
-
render(): React.ReactNode;
|
|
30
|
-
getView(): View;
|
|
31
|
-
private $getComponentsToRender;
|
|
32
|
-
private $getChildren;
|
|
33
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View } from './View';
|
|
3
|
+
import { RouteMatcher } from './RouteMatcher';
|
|
4
|
+
import { RouterStrategy } from './RouterStrategy';
|
|
5
|
+
import { TransitionStrategy } from 'TransitionStrategy';
|
|
6
|
+
export interface IRouteProps<T> {
|
|
7
|
+
url: string;
|
|
8
|
+
component: React.ComponentClass<any>;
|
|
9
|
+
index?: boolean;
|
|
10
|
+
entryTransition?: TransitionStrategy;
|
|
11
|
+
exitTransition?: TransitionStrategy;
|
|
12
|
+
base?: string;
|
|
13
|
+
componentProps?: T;
|
|
14
|
+
matcher?: RouteMatcher;
|
|
15
|
+
}
|
|
16
|
+
export interface IComponentProps {
|
|
17
|
+
url: string;
|
|
18
|
+
router: RouterStrategy;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
export interface IRouteState {
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* This class represents a route that renders a {@link View} component
|
|
25
|
+
*/
|
|
26
|
+
export declare class Route<TComponentProps extends IComponentProps = IComponentProps, TRouteProps extends IRouteProps<TComponentProps> = IRouteProps<TComponentProps>, TRouteState extends IRouteState = IRouteState> extends React.Component<TRouteProps, TRouteState> {
|
|
27
|
+
private $node;
|
|
28
|
+
constructor(props: TRouteProps);
|
|
29
|
+
render(): React.ReactNode;
|
|
30
|
+
getView(): View;
|
|
31
|
+
private $getComponentsToRender;
|
|
32
|
+
private $getChildren;
|
|
33
|
+
}
|
|
@@ -1,31 +1,30 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param {React.ReactElement}
|
|
7
|
-
* @
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @param
|
|
27
|
-
* @param
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { RouterStrategy } from './RouterStrategy';
|
|
3
|
+
/**
|
|
4
|
+
* Will be invoked when no routes are found. Default implementation is to simply return the `indexRoute`.
|
|
5
|
+
* @param {React.ReactElement} indexRoute The `ReactElement` of a `Route`
|
|
6
|
+
* @param {Array<React.ReactElement>} routes An array of `ReactElement` of `Route`
|
|
7
|
+
* @returns {React.ReactElement} An `ReactElement` of a `Route`
|
|
8
|
+
*/
|
|
9
|
+
export interface IOnNoRouteFunction {
|
|
10
|
+
(indexRoute: React.ReactElement, routes: Array<React.ReactElement>): React.ReactElement;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This class is reponsible for determing which route to render
|
|
14
|
+
* based on the URL and the route url patterns.
|
|
15
|
+
*/
|
|
16
|
+
export declare class RouteMatcher {
|
|
17
|
+
private $strategy;
|
|
18
|
+
constructor(routerStrategy: RouterStrategy);
|
|
19
|
+
private $defaultNoRouteFunction;
|
|
20
|
+
/**
|
|
21
|
+
* Matches the url to the appropriate renderable route
|
|
22
|
+
*
|
|
23
|
+
* @param url
|
|
24
|
+
* @param children
|
|
25
|
+
* @param base
|
|
26
|
+
* @param indexRoute
|
|
27
|
+
* @param onNoRoute
|
|
28
|
+
*/
|
|
29
|
+
match(url: string, children: Array<React.ReactElement>, base: string, indexRoute?: React.ReactElement, onNoRoute?: IOnNoRouteFunction): React.ReactElement;
|
|
30
|
+
}
|
package/dist/src/Router.d.ts
CHANGED
|
@@ -1,85 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
onNoRoute?: IOnNoRoute;
|
|
10
|
-
}
|
|
11
|
-
export interface IRouterState {
|
|
12
|
-
strategy: RouterStrategy;
|
|
13
|
-
url: string;
|
|
14
|
-
shouldTransition: boolean;
|
|
15
|
-
}
|
|
16
|
-
export declare class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
|
|
17
|
-
state: IRouterState;
|
|
18
|
-
private $lastRenderedRoute;
|
|
19
|
-
private $matcher;
|
|
20
|
-
private $awaitingTransition;
|
|
21
|
-
private $incomingRoute;
|
|
22
|
-
private $exitingRoute;
|
|
23
|
-
private static $instance;
|
|
24
|
-
constructor(props: TRouterProps);
|
|
25
|
-
static getInstance(): RouterStrategy;
|
|
26
|
-
/**
|
|
27
|
-
* Gets the current routing strategy
|
|
28
|
-
*/
|
|
29
|
-
getRouterStrategy(): RouterStrategy;
|
|
30
|
-
/**
|
|
31
|
-
* @ignore
|
|
32
|
-
*/
|
|
33
|
-
private $onURLChange;
|
|
34
|
-
componentDidMount(): void;
|
|
35
|
-
/**
|
|
36
|
-
* @ignore
|
|
37
|
-
*/
|
|
38
|
-
UNSAFE_componentWillReceiveProps(nextProps: TRouterProps): void;
|
|
39
|
-
/**
|
|
40
|
-
* @ignore
|
|
41
|
-
*/
|
|
42
|
-
componentWillUnmount(): void;
|
|
43
|
-
/**
|
|
44
|
-
* @ignore
|
|
45
|
-
*/
|
|
46
|
-
render(): React.ReactNode;
|
|
47
|
-
/**
|
|
48
|
-
* @ignore
|
|
49
|
-
*/
|
|
50
|
-
componentDidUpdate(): void;
|
|
51
|
-
/**
|
|
52
|
-
* Gets the number of history entries. Note this does not count the browser history.
|
|
53
|
-
* Only the history kept track during the life-cycle of the app.
|
|
54
|
-
*/
|
|
55
|
-
getHistoryLength(): number;
|
|
56
|
-
/**
|
|
57
|
-
* Gets the scroll restoration mode
|
|
58
|
-
*/
|
|
59
|
-
getScrollRestoration(): ScrollRestoration;
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param to An integer, positive means go forward, negative means go backwards. E.g:
|
|
63
|
-
* `1` move forward one step
|
|
64
|
-
* `-1` move backward one step
|
|
65
|
-
* `0` navigate to the current page (This is essentially a no-op)
|
|
66
|
-
*/
|
|
67
|
-
go(to: number): void;
|
|
68
|
-
/**
|
|
69
|
-
* Go back one step. This is an alias for [pushState(-1)]{@link go}.
|
|
70
|
-
*/
|
|
71
|
-
back(): void;
|
|
72
|
-
/**
|
|
73
|
-
* Go forward one step. This is an alias for [pushState(1)]{@link go}.
|
|
74
|
-
*/
|
|
75
|
-
forward(): void;
|
|
76
|
-
/**
|
|
77
|
-
* Gets the potential routes
|
|
78
|
-
*/
|
|
79
|
-
private $getChildren;
|
|
80
|
-
/**
|
|
81
|
-
* Finds the index route. Returns null if there are no indexed routes.
|
|
82
|
-
*/
|
|
83
|
-
private $getIndexRoute;
|
|
84
|
-
}
|
|
85
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RouterStrategy } from './RouterStrategy';
|
|
3
|
+
import { IRouterStrategyClass } from './IRouterStrategyClass';
|
|
4
|
+
import { IOnNoRoute } from './IOnNoRoute';
|
|
5
|
+
export interface IRouterProps {
|
|
6
|
+
strategy?: IRouterStrategyClass;
|
|
7
|
+
component: React.ComponentClass<any>;
|
|
8
|
+
children?: React.ReactNode;
|
|
9
|
+
onNoRoute?: IOnNoRoute;
|
|
10
|
+
}
|
|
11
|
+
export interface IRouterState {
|
|
12
|
+
strategy: RouterStrategy;
|
|
13
|
+
url: string;
|
|
14
|
+
shouldTransition: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class Router<TRouterProps extends IRouterProps = IRouterProps> extends React.Component<TRouterProps, IRouterState> {
|
|
17
|
+
state: IRouterState;
|
|
18
|
+
private $lastRenderedRoute;
|
|
19
|
+
private $matcher;
|
|
20
|
+
private $awaitingTransition;
|
|
21
|
+
private $incomingRoute;
|
|
22
|
+
private $exitingRoute;
|
|
23
|
+
private static $instance;
|
|
24
|
+
constructor(props: TRouterProps);
|
|
25
|
+
static getInstance(): RouterStrategy;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the current routing strategy
|
|
28
|
+
*/
|
|
29
|
+
getRouterStrategy(): RouterStrategy;
|
|
30
|
+
/**
|
|
31
|
+
* @ignore
|
|
32
|
+
*/
|
|
33
|
+
private $onURLChange;
|
|
34
|
+
componentDidMount(): void;
|
|
35
|
+
/**
|
|
36
|
+
* @ignore
|
|
37
|
+
*/
|
|
38
|
+
UNSAFE_componentWillReceiveProps(nextProps: TRouterProps): void;
|
|
39
|
+
/**
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
componentWillUnmount(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @ignore
|
|
45
|
+
*/
|
|
46
|
+
render(): React.ReactNode;
|
|
47
|
+
/**
|
|
48
|
+
* @ignore
|
|
49
|
+
*/
|
|
50
|
+
componentDidUpdate(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the number of history entries. Note this does not count the browser history.
|
|
53
|
+
* Only the history kept track during the life-cycle of the app.
|
|
54
|
+
*/
|
|
55
|
+
getHistoryLength(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the scroll restoration mode
|
|
58
|
+
*/
|
|
59
|
+
getScrollRestoration(): ScrollRestoration;
|
|
60
|
+
/**
|
|
61
|
+
*
|
|
62
|
+
* @param to An integer, positive means go forward, negative means go backwards. E.g:
|
|
63
|
+
* `1` move forward one step
|
|
64
|
+
* `-1` move backward one step
|
|
65
|
+
* `0` navigate to the current page (This is essentially a no-op)
|
|
66
|
+
*/
|
|
67
|
+
go(to: number): void;
|
|
68
|
+
/**
|
|
69
|
+
* Go back one step. This is an alias for [pushState(-1)]{@link go}.
|
|
70
|
+
*/
|
|
71
|
+
back(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Go forward one step. This is an alias for [pushState(1)]{@link go}.
|
|
74
|
+
*/
|
|
75
|
+
forward(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Gets the potential routes
|
|
78
|
+
*/
|
|
79
|
+
private $getChildren;
|
|
80
|
+
/**
|
|
81
|
+
* Finds the index route. Returns null if there are no indexed routes.
|
|
82
|
+
*/
|
|
83
|
+
private $getIndexRoute;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @deprecated Use Router.getInstance() instead.
|
|
87
|
+
* @returns {RouterStrategy}
|
|
88
|
+
*/
|
|
89
|
+
export declare let getRouter: () => RouterStrategy;
|