@shuvi/router 1.0.21 → 1.0.22
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/esm/router.js +68 -68
- package/lib/router.js +68 -68
- package/package.json +2 -2
package/esm/router.js
CHANGED
|
@@ -26,6 +26,74 @@ class Router {
|
|
|
26
26
|
this._beforeEachs = createEvents();
|
|
27
27
|
this._beforeResolves = createEvents();
|
|
28
28
|
this._afterEachs = createEvents();
|
|
29
|
+
this.init = () => {
|
|
30
|
+
const setup = () => this._history.setup();
|
|
31
|
+
this._history.transitionTo(this._getCurrent(), {
|
|
32
|
+
onTransition: setup,
|
|
33
|
+
onAbort: setup
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
};
|
|
37
|
+
this.push = (to, state) => {
|
|
38
|
+
return this._history.push(to, { state });
|
|
39
|
+
};
|
|
40
|
+
this.replace = (to, state) => {
|
|
41
|
+
return this._history.replace(to, { state });
|
|
42
|
+
};
|
|
43
|
+
this.go = (delta) => {
|
|
44
|
+
this._history.go(delta);
|
|
45
|
+
};
|
|
46
|
+
this.back = () => {
|
|
47
|
+
this._history.back();
|
|
48
|
+
};
|
|
49
|
+
this.forward = () => {
|
|
50
|
+
this._history.forward();
|
|
51
|
+
};
|
|
52
|
+
this.block = (blocker) => {
|
|
53
|
+
return this._history.block(blocker);
|
|
54
|
+
};
|
|
55
|
+
this.listen = (listener) => {
|
|
56
|
+
return this._listeners.push(listener);
|
|
57
|
+
};
|
|
58
|
+
this.beforeEach = (listener) => {
|
|
59
|
+
return this._beforeEachs.push(listener);
|
|
60
|
+
};
|
|
61
|
+
this.beforeResolve = (listener) => {
|
|
62
|
+
return this._beforeResolves.push(listener);
|
|
63
|
+
};
|
|
64
|
+
this.afterEach = (listener) => {
|
|
65
|
+
return this._afterEachs.push(listener);
|
|
66
|
+
};
|
|
67
|
+
this.resolve = (to, from) => {
|
|
68
|
+
return this._history.resolve(to, from ? joinPaths([this._basename, from]) : this._basename);
|
|
69
|
+
};
|
|
70
|
+
this.match = (to) => {
|
|
71
|
+
const { _routes: routes, _basename: basename } = this;
|
|
72
|
+
const matches = matchRoutes(routes, to, basename);
|
|
73
|
+
return matches || [];
|
|
74
|
+
};
|
|
75
|
+
this.replaceRoutes = (routes) => {
|
|
76
|
+
if (this._ready) {
|
|
77
|
+
this._ready = false;
|
|
78
|
+
this._readyDefer = createDefer();
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
// do nothing
|
|
82
|
+
// keep _readyDefer as it is, cause user might called router.ready()
|
|
83
|
+
}
|
|
84
|
+
if (this._cancleHandler) {
|
|
85
|
+
// cancel current transition
|
|
86
|
+
this._cancleHandler();
|
|
87
|
+
this._cancleHandler = null;
|
|
88
|
+
}
|
|
89
|
+
this._routes = createRoutesFromArray(routes);
|
|
90
|
+
this._current = START;
|
|
91
|
+
const setup = () => this._history.setup();
|
|
92
|
+
this._history.transitionTo(this._getCurrent(), {
|
|
93
|
+
onTransition: setup,
|
|
94
|
+
onAbort: setup
|
|
95
|
+
});
|
|
96
|
+
};
|
|
29
97
|
this._basename = normalizeBase(basename);
|
|
30
98
|
this._history = history;
|
|
31
99
|
this._routes = createRoutesFromArray(routes);
|
|
@@ -44,74 +112,6 @@ class Router {
|
|
|
44
112
|
get action() {
|
|
45
113
|
return this._history.action;
|
|
46
114
|
}
|
|
47
|
-
init() {
|
|
48
|
-
const setup = () => this._history.setup();
|
|
49
|
-
this._history.transitionTo(this._getCurrent(), {
|
|
50
|
-
onTransition: setup,
|
|
51
|
-
onAbort: setup
|
|
52
|
-
});
|
|
53
|
-
return this;
|
|
54
|
-
}
|
|
55
|
-
push(to, state) {
|
|
56
|
-
return this._history.push(to, { state });
|
|
57
|
-
}
|
|
58
|
-
replace(to, state) {
|
|
59
|
-
return this._history.replace(to, { state });
|
|
60
|
-
}
|
|
61
|
-
go(delta) {
|
|
62
|
-
this._history.go(delta);
|
|
63
|
-
}
|
|
64
|
-
back() {
|
|
65
|
-
this._history.back();
|
|
66
|
-
}
|
|
67
|
-
forward() {
|
|
68
|
-
this._history.forward();
|
|
69
|
-
}
|
|
70
|
-
block(blocker) {
|
|
71
|
-
return this._history.block(blocker);
|
|
72
|
-
}
|
|
73
|
-
listen(listener) {
|
|
74
|
-
return this._listeners.push(listener);
|
|
75
|
-
}
|
|
76
|
-
beforeEach(listener) {
|
|
77
|
-
return this._beforeEachs.push(listener);
|
|
78
|
-
}
|
|
79
|
-
beforeResolve(listener) {
|
|
80
|
-
return this._beforeResolves.push(listener);
|
|
81
|
-
}
|
|
82
|
-
afterEach(listener) {
|
|
83
|
-
return this._afterEachs.push(listener);
|
|
84
|
-
}
|
|
85
|
-
resolve(to, from) {
|
|
86
|
-
return this._history.resolve(to, from ? joinPaths([this._basename, from]) : this._basename);
|
|
87
|
-
}
|
|
88
|
-
match(to) {
|
|
89
|
-
const { _routes: routes, _basename: basename } = this;
|
|
90
|
-
const matches = matchRoutes(routes, to, basename);
|
|
91
|
-
return matches || [];
|
|
92
|
-
}
|
|
93
|
-
replaceRoutes(routes) {
|
|
94
|
-
if (this._ready) {
|
|
95
|
-
this._ready = false;
|
|
96
|
-
this._readyDefer = createDefer();
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// do nothing
|
|
100
|
-
// keep _readyDefer as it is, cause user might called router.ready()
|
|
101
|
-
}
|
|
102
|
-
if (this._cancleHandler) {
|
|
103
|
-
// cancel current transition
|
|
104
|
-
this._cancleHandler();
|
|
105
|
-
this._cancleHandler = null;
|
|
106
|
-
}
|
|
107
|
-
this._routes = createRoutesFromArray(routes);
|
|
108
|
-
this._current = START;
|
|
109
|
-
const setup = () => this._history.setup();
|
|
110
|
-
this._history.transitionTo(this._getCurrent(), {
|
|
111
|
-
onTransition: setup,
|
|
112
|
-
onAbort: setup
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
115
|
/*
|
|
116
116
|
The Full Navigation Resolution Flow for shuvi/router
|
|
117
117
|
1. Navigation triggered.
|
package/lib/router.js
CHANGED
|
@@ -29,6 +29,74 @@ class Router {
|
|
|
29
29
|
this._beforeEachs = (0, utils_1.createEvents)();
|
|
30
30
|
this._beforeResolves = (0, utils_1.createEvents)();
|
|
31
31
|
this._afterEachs = (0, utils_1.createEvents)();
|
|
32
|
+
this.init = () => {
|
|
33
|
+
const setup = () => this._history.setup();
|
|
34
|
+
this._history.transitionTo(this._getCurrent(), {
|
|
35
|
+
onTransition: setup,
|
|
36
|
+
onAbort: setup
|
|
37
|
+
});
|
|
38
|
+
return this;
|
|
39
|
+
};
|
|
40
|
+
this.push = (to, state) => {
|
|
41
|
+
return this._history.push(to, { state });
|
|
42
|
+
};
|
|
43
|
+
this.replace = (to, state) => {
|
|
44
|
+
return this._history.replace(to, { state });
|
|
45
|
+
};
|
|
46
|
+
this.go = (delta) => {
|
|
47
|
+
this._history.go(delta);
|
|
48
|
+
};
|
|
49
|
+
this.back = () => {
|
|
50
|
+
this._history.back();
|
|
51
|
+
};
|
|
52
|
+
this.forward = () => {
|
|
53
|
+
this._history.forward();
|
|
54
|
+
};
|
|
55
|
+
this.block = (blocker) => {
|
|
56
|
+
return this._history.block(blocker);
|
|
57
|
+
};
|
|
58
|
+
this.listen = (listener) => {
|
|
59
|
+
return this._listeners.push(listener);
|
|
60
|
+
};
|
|
61
|
+
this.beforeEach = (listener) => {
|
|
62
|
+
return this._beforeEachs.push(listener);
|
|
63
|
+
};
|
|
64
|
+
this.beforeResolve = (listener) => {
|
|
65
|
+
return this._beforeResolves.push(listener);
|
|
66
|
+
};
|
|
67
|
+
this.afterEach = (listener) => {
|
|
68
|
+
return this._afterEachs.push(listener);
|
|
69
|
+
};
|
|
70
|
+
this.resolve = (to, from) => {
|
|
71
|
+
return this._history.resolve(to, from ? (0, utils_1.joinPaths)([this._basename, from]) : this._basename);
|
|
72
|
+
};
|
|
73
|
+
this.match = (to) => {
|
|
74
|
+
const { _routes: routes, _basename: basename } = this;
|
|
75
|
+
const matches = (0, matchRoutes_1.matchRoutes)(routes, to, basename);
|
|
76
|
+
return matches || [];
|
|
77
|
+
};
|
|
78
|
+
this.replaceRoutes = (routes) => {
|
|
79
|
+
if (this._ready) {
|
|
80
|
+
this._ready = false;
|
|
81
|
+
this._readyDefer = (0, defer_1.createDefer)();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// do nothing
|
|
85
|
+
// keep _readyDefer as it is, cause user might called router.ready()
|
|
86
|
+
}
|
|
87
|
+
if (this._cancleHandler) {
|
|
88
|
+
// cancel current transition
|
|
89
|
+
this._cancleHandler();
|
|
90
|
+
this._cancleHandler = null;
|
|
91
|
+
}
|
|
92
|
+
this._routes = (0, createRoutesFromArray_1.createRoutesFromArray)(routes);
|
|
93
|
+
this._current = START;
|
|
94
|
+
const setup = () => this._history.setup();
|
|
95
|
+
this._history.transitionTo(this._getCurrent(), {
|
|
96
|
+
onTransition: setup,
|
|
97
|
+
onAbort: setup
|
|
98
|
+
});
|
|
99
|
+
};
|
|
32
100
|
this._basename = (0, utils_1.normalizeBase)(basename);
|
|
33
101
|
this._history = history;
|
|
34
102
|
this._routes = (0, createRoutesFromArray_1.createRoutesFromArray)(routes);
|
|
@@ -47,74 +115,6 @@ class Router {
|
|
|
47
115
|
get action() {
|
|
48
116
|
return this._history.action;
|
|
49
117
|
}
|
|
50
|
-
init() {
|
|
51
|
-
const setup = () => this._history.setup();
|
|
52
|
-
this._history.transitionTo(this._getCurrent(), {
|
|
53
|
-
onTransition: setup,
|
|
54
|
-
onAbort: setup
|
|
55
|
-
});
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
push(to, state) {
|
|
59
|
-
return this._history.push(to, { state });
|
|
60
|
-
}
|
|
61
|
-
replace(to, state) {
|
|
62
|
-
return this._history.replace(to, { state });
|
|
63
|
-
}
|
|
64
|
-
go(delta) {
|
|
65
|
-
this._history.go(delta);
|
|
66
|
-
}
|
|
67
|
-
back() {
|
|
68
|
-
this._history.back();
|
|
69
|
-
}
|
|
70
|
-
forward() {
|
|
71
|
-
this._history.forward();
|
|
72
|
-
}
|
|
73
|
-
block(blocker) {
|
|
74
|
-
return this._history.block(blocker);
|
|
75
|
-
}
|
|
76
|
-
listen(listener) {
|
|
77
|
-
return this._listeners.push(listener);
|
|
78
|
-
}
|
|
79
|
-
beforeEach(listener) {
|
|
80
|
-
return this._beforeEachs.push(listener);
|
|
81
|
-
}
|
|
82
|
-
beforeResolve(listener) {
|
|
83
|
-
return this._beforeResolves.push(listener);
|
|
84
|
-
}
|
|
85
|
-
afterEach(listener) {
|
|
86
|
-
return this._afterEachs.push(listener);
|
|
87
|
-
}
|
|
88
|
-
resolve(to, from) {
|
|
89
|
-
return this._history.resolve(to, from ? (0, utils_1.joinPaths)([this._basename, from]) : this._basename);
|
|
90
|
-
}
|
|
91
|
-
match(to) {
|
|
92
|
-
const { _routes: routes, _basename: basename } = this;
|
|
93
|
-
const matches = (0, matchRoutes_1.matchRoutes)(routes, to, basename);
|
|
94
|
-
return matches || [];
|
|
95
|
-
}
|
|
96
|
-
replaceRoutes(routes) {
|
|
97
|
-
if (this._ready) {
|
|
98
|
-
this._ready = false;
|
|
99
|
-
this._readyDefer = (0, defer_1.createDefer)();
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
// do nothing
|
|
103
|
-
// keep _readyDefer as it is, cause user might called router.ready()
|
|
104
|
-
}
|
|
105
|
-
if (this._cancleHandler) {
|
|
106
|
-
// cancel current transition
|
|
107
|
-
this._cancleHandler();
|
|
108
|
-
this._cancleHandler = null;
|
|
109
|
-
}
|
|
110
|
-
this._routes = (0, createRoutesFromArray_1.createRoutesFromArray)(routes);
|
|
111
|
-
this._current = START;
|
|
112
|
-
const setup = () => this._history.setup();
|
|
113
|
-
this._history.transitionTo(this._getCurrent(), {
|
|
114
|
-
onTransition: setup,
|
|
115
|
-
onAbort: setup
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
118
|
/*
|
|
119
119
|
The Full Navigation Resolution Flow for shuvi/router
|
|
120
120
|
1. Navigation triggered.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shuvi/router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/shuvijs/shuvi.git",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"node": ">= 16.0.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@shuvi/utils": "1.0.
|
|
31
|
+
"@shuvi/utils": "1.0.22",
|
|
32
32
|
"query-string": "6.13.8"
|
|
33
33
|
}
|
|
34
34
|
}
|