@ray-js/router 0.3.0-beta.1c347991
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/README.md +1 -0
- package/lib/Router.d.ts +22 -0
- package/lib/Router.js +135 -0
- package/lib/RouterScheduler.d.ts +32 -0
- package/lib/RouterScheduler.js +145 -0
- package/lib/history/index.d.ts +10 -0
- package/lib/history/index.js +87 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +45 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @ray-js/router
|
package/lib/Router.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Router as TRouter } from '@ray-js/types';
|
|
2
|
+
import { RouterScheduler } from './RouterScheduler';
|
|
3
|
+
export declare class Router implements TRouter {
|
|
4
|
+
/**
|
|
5
|
+
* 页面路由调度器
|
|
6
|
+
*/
|
|
7
|
+
scheduler: RouterScheduler;
|
|
8
|
+
/**
|
|
9
|
+
* 当前环境地址栏
|
|
10
|
+
*/
|
|
11
|
+
$href: string;
|
|
12
|
+
constructor(options: {
|
|
13
|
+
scheduler: RouterScheduler;
|
|
14
|
+
});
|
|
15
|
+
private normalizeRoute;
|
|
16
|
+
push(to: string): void;
|
|
17
|
+
replace(to: string): void;
|
|
18
|
+
go(delta: number): void;
|
|
19
|
+
back(): void;
|
|
20
|
+
reload(to: string): void;
|
|
21
|
+
get hostHref(): string;
|
|
22
|
+
}
|
package/lib/Router.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import "core-js/modules/es.string.starts-with.js";
|
|
6
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
7
|
+
import "core-js/modules/es.string.search.js";
|
|
8
|
+
import "core-js/modules/es.string.replace.js";
|
|
9
|
+
import { url } from '@ray-js/library';
|
|
10
|
+
import { history } from './history';
|
|
11
|
+
export var Router = /*#__PURE__*/function () {
|
|
12
|
+
/**
|
|
13
|
+
* 页面路由调度器
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* 当前环境地址栏
|
|
18
|
+
*/
|
|
19
|
+
function Router(options) {
|
|
20
|
+
_classCallCheck(this, Router);
|
|
21
|
+
|
|
22
|
+
this.scheduler = options.scheduler;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
_createClass(Router, [{
|
|
26
|
+
key: "normalizeRoute",
|
|
27
|
+
value: function () {
|
|
28
|
+
var _normalizeRoute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
|
|
29
|
+
var to, _url$parse, pathname, search, hash;
|
|
30
|
+
|
|
31
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
32
|
+
while (1) {
|
|
33
|
+
switch (_context.prev = _context.next) {
|
|
34
|
+
case 0:
|
|
35
|
+
to = params.to; // FIXME: 绝对路径是否需要支持?
|
|
36
|
+
|
|
37
|
+
if (!(to.startsWith('//') || to.startsWith('http'))) {
|
|
38
|
+
_context.next = 3;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _context.abrupt("return", {
|
|
43
|
+
to: to
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
case 3:
|
|
47
|
+
if (this.scheduler.basename) {
|
|
48
|
+
to = this.scheduler.basename + to;
|
|
49
|
+
} // TODO: Web 应用下重复进入一个路由
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if (this.$href) {
|
|
53
|
+
_url$parse = url.parse(this.$href), pathname = _url$parse.pathname, search = _url$parse.search, hash = _url$parse.hash;
|
|
54
|
+
|
|
55
|
+
if (url.format({
|
|
56
|
+
pathname: pathname,
|
|
57
|
+
search: search,
|
|
58
|
+
hash: hash
|
|
59
|
+
}) === to) {
|
|
60
|
+
console.warn('duplicate route to:', to);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return _context.abrupt("return", {
|
|
65
|
+
to: to
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
case 6:
|
|
69
|
+
case "end":
|
|
70
|
+
return _context.stop();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}, _callee, this);
|
|
74
|
+
}));
|
|
75
|
+
|
|
76
|
+
function normalizeRoute() {
|
|
77
|
+
return _normalizeRoute.apply(this, arguments);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return normalizeRoute;
|
|
81
|
+
}()
|
|
82
|
+
}, {
|
|
83
|
+
key: "push",
|
|
84
|
+
value: function push(to) {
|
|
85
|
+
this.normalizeRoute({
|
|
86
|
+
to: to
|
|
87
|
+
}).then(function (_ref) {
|
|
88
|
+
var to = _ref.to;
|
|
89
|
+
history.push(to);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}, {
|
|
93
|
+
key: "replace",
|
|
94
|
+
value: function replace(to) {
|
|
95
|
+
this.normalizeRoute({
|
|
96
|
+
to: to
|
|
97
|
+
}).then(function (_ref2) {
|
|
98
|
+
var to = _ref2.to;
|
|
99
|
+
history.replace(to);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "go",
|
|
104
|
+
value: function go(delta) {
|
|
105
|
+
// 在应用堆栈内进行跳转
|
|
106
|
+
history.go(delta);
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "back",
|
|
110
|
+
value: function back() {
|
|
111
|
+
history.goBack();
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "reload",
|
|
115
|
+
value: function reload(to) {
|
|
116
|
+
if (to) {
|
|
117
|
+
this.normalizeRoute({
|
|
118
|
+
to: to
|
|
119
|
+
}).then(function (_ref3) {
|
|
120
|
+
var to = _ref3.to;
|
|
121
|
+
window.location.href = to;
|
|
122
|
+
});
|
|
123
|
+
} else {
|
|
124
|
+
window.location.reload();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}, {
|
|
128
|
+
key: "hostHref",
|
|
129
|
+
get: function get() {
|
|
130
|
+
return window.location.href;
|
|
131
|
+
}
|
|
132
|
+
}]);
|
|
133
|
+
|
|
134
|
+
return Router;
|
|
135
|
+
}();
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Page, Pages, RouterScheduler as IRouterScheduler, Routes, TabBar } from '@ray-js/types';
|
|
2
|
+
declare type EventMembers = 'routeChange';
|
|
3
|
+
/**
|
|
4
|
+
* web 环境下的路由协调器
|
|
5
|
+
*/
|
|
6
|
+
export declare class RouterScheduler extends IRouterScheduler<Page> {
|
|
7
|
+
private $currentRoute;
|
|
8
|
+
private $listeners;
|
|
9
|
+
$entityMap: Record<string, Page[]>;
|
|
10
|
+
basename: string;
|
|
11
|
+
/**
|
|
12
|
+
* 当前调度器的 route 地址
|
|
13
|
+
*/
|
|
14
|
+
get currentRoute(): string;
|
|
15
|
+
set currentRoute(val: string);
|
|
16
|
+
on(event: EventMembers, fn: Function): () => void;
|
|
17
|
+
emit(event: EventMembers, ...args: any[]): void;
|
|
18
|
+
/**
|
|
19
|
+
* 初始化路由,注册应用声明的路由,并处理映射关系
|
|
20
|
+
*/
|
|
21
|
+
registryPages(params: {
|
|
22
|
+
routes: Routes;
|
|
23
|
+
pages: Pages;
|
|
24
|
+
tabBar: TabBar;
|
|
25
|
+
}): void;
|
|
26
|
+
getMatchedPage(pathname: string): Page & {
|
|
27
|
+
params: object;
|
|
28
|
+
pathname: string;
|
|
29
|
+
};
|
|
30
|
+
addPage(page: Page): void;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
5
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
6
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
7
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
8
|
+
import "core-js/modules/es.array.concat.js";
|
|
9
|
+
import "core-js/modules/es.array.splice.js";
|
|
10
|
+
import "core-js/modules/es.array.index-of.js";
|
|
11
|
+
import "core-js/modules/es.object.to-string.js";
|
|
12
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
13
|
+
import { RouterScheduler as IRouterScheduler } from '@ray-js/types';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* web 环境下的路由协调器
|
|
17
|
+
*/
|
|
18
|
+
export var RouterScheduler = /*#__PURE__*/function (_IRouterScheduler) {
|
|
19
|
+
_inherits(RouterScheduler, _IRouterScheduler);
|
|
20
|
+
|
|
21
|
+
var _super = _createSuper(RouterScheduler);
|
|
22
|
+
|
|
23
|
+
function RouterScheduler() {
|
|
24
|
+
var _this;
|
|
25
|
+
|
|
26
|
+
_classCallCheck(this, RouterScheduler);
|
|
27
|
+
|
|
28
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
29
|
+
args[_key] = arguments[_key];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
33
|
+
|
|
34
|
+
_defineProperty(_assertThisInitialized(_this), "$currentRoute", '');
|
|
35
|
+
|
|
36
|
+
_defineProperty(_assertThisInitialized(_this), "$listeners", {});
|
|
37
|
+
|
|
38
|
+
_defineProperty(_assertThisInitialized(_this), "$entityMap", {});
|
|
39
|
+
|
|
40
|
+
_defineProperty(_assertThisInitialized(_this), "basename", '');
|
|
41
|
+
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
_createClass(RouterScheduler, [{
|
|
46
|
+
key: "currentRoute",
|
|
47
|
+
get:
|
|
48
|
+
/**
|
|
49
|
+
* 当前调度器的 route 地址
|
|
50
|
+
*/
|
|
51
|
+
function get() {
|
|
52
|
+
return this.$currentRoute;
|
|
53
|
+
},
|
|
54
|
+
set: function set(val) {
|
|
55
|
+
if (val !== this.currentRoute) {
|
|
56
|
+
this.$currentRoute = val;
|
|
57
|
+
this.emit('routeChange', this.currentRoute);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}, {
|
|
61
|
+
key: "on",
|
|
62
|
+
value: function on(event, fn) {
|
|
63
|
+
if (!this.$listeners[event]) {
|
|
64
|
+
this.$listeners[event] = [];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
var events = this.$listeners[event];
|
|
68
|
+
events.push(fn);
|
|
69
|
+
return function () {
|
|
70
|
+
events.splice(events.indexOf(fn), 1);
|
|
71
|
+
};
|
|
72
|
+
} // 给 TabBar 监听,用于处理当前高亮状态
|
|
73
|
+
|
|
74
|
+
}, {
|
|
75
|
+
key: "emit",
|
|
76
|
+
value: function emit(event) {
|
|
77
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
78
|
+
args[_key2 - 1] = arguments[_key2];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var fns = this.$listeners[event];
|
|
82
|
+
|
|
83
|
+
if (Array.isArray(fns)) {
|
|
84
|
+
fns.forEach(function (fn) {
|
|
85
|
+
fn.apply(void 0, args);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 初始化路由,注册应用声明的路由,并处理映射关系
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
}, {
|
|
94
|
+
key: "registryPages",
|
|
95
|
+
value: function registryPages(params) {
|
|
96
|
+
var _this2 = this;
|
|
97
|
+
|
|
98
|
+
var pages = params.pages,
|
|
99
|
+
tabBar = params.tabBar;
|
|
100
|
+
var tabBarList = tabBar.list || [];
|
|
101
|
+
pages.forEach(function (page) {
|
|
102
|
+
var isTabBar = tabBarList.some(function (item) {
|
|
103
|
+
if (item.route) {
|
|
104
|
+
return page.route === item.route;
|
|
105
|
+
} else if (item.id) {
|
|
106
|
+
return page.id === item.id;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return false;
|
|
110
|
+
});
|
|
111
|
+
page.route = _this2.basename + page.route;
|
|
112
|
+
page.originalRoute = page.route;
|
|
113
|
+
|
|
114
|
+
_this2.addPage(_objectSpread(_objectSpread({}, page), {}, {
|
|
115
|
+
isTabBar: isTabBar
|
|
116
|
+
}));
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, {
|
|
120
|
+
key: "getMatchedPage",
|
|
121
|
+
value: function getMatchedPage(pathname) {
|
|
122
|
+
// 适配 `domain.com/basename/` & `domain.com/basename`
|
|
123
|
+
// 注册首页使用的是 `/` 需预处理
|
|
124
|
+
if (this.basename === pathname) {
|
|
125
|
+
pathname = pathname + '/';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.currentRoute = pathname;
|
|
129
|
+
return this.matchPageByPathname(pathname);
|
|
130
|
+
}
|
|
131
|
+
}, {
|
|
132
|
+
key: "addPage",
|
|
133
|
+
value: function addPage(page) {
|
|
134
|
+
var depth = this.slashDepth(page.route);
|
|
135
|
+
|
|
136
|
+
if (!this.$entityMap[depth]) {
|
|
137
|
+
this.$entityMap[depth] = [];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
this.$entityMap[depth].push(page);
|
|
141
|
+
}
|
|
142
|
+
}]);
|
|
143
|
+
|
|
144
|
+
return RouterScheduler;
|
|
145
|
+
}(IRouterScheduler);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { History } from 'history';
|
|
2
|
+
import { MatchedPage, Page, PageComponent, RouterScheduler } from '@ray-js/types';
|
|
3
|
+
export declare let history: History;
|
|
4
|
+
export declare function createHistory(options: {
|
|
5
|
+
basename?: string;
|
|
6
|
+
scheduler: RouterScheduler<Page>;
|
|
7
|
+
onChange: (component: PageComponent, params: {
|
|
8
|
+
page: MatchedPage;
|
|
9
|
+
}) => void;
|
|
10
|
+
}): History<unknown>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import "core-js/modules/es.object.to-string.js";
|
|
4
|
+
import "core-js/modules/es.promise.js";
|
|
5
|
+
import { createBrowserHistory } from 'history';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
export var history;
|
|
8
|
+
var changeKey = '';
|
|
9
|
+
export function createHistory(options) {
|
|
10
|
+
var scheduler = options.scheduler;
|
|
11
|
+
history = createBrowserHistory(options);
|
|
12
|
+
history.listen( /*#__PURE__*/function () {
|
|
13
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(historyLocation) {
|
|
14
|
+
var key, pathname, matchedPage, page, NotFound;
|
|
15
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
16
|
+
while (1) {
|
|
17
|
+
switch (_context.prev = _context.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
key = historyLocation.key, pathname = historyLocation.pathname;
|
|
20
|
+
|
|
21
|
+
if (!(key && key === changeKey)) {
|
|
22
|
+
_context.next = 3;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return _context.abrupt("return");
|
|
27
|
+
|
|
28
|
+
case 3:
|
|
29
|
+
changeKey = key;
|
|
30
|
+
matchedPage = scheduler.getMatchedPage(pathname);
|
|
31
|
+
|
|
32
|
+
if (!matchedPage) {
|
|
33
|
+
// 兜底通配页面
|
|
34
|
+
matchedPage = scheduler.getMatchedPage('*');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!matchedPage) {
|
|
38
|
+
_context.next = 13;
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
_context.next = 9;
|
|
43
|
+
return matchedPage.component();
|
|
44
|
+
|
|
45
|
+
case 9:
|
|
46
|
+
page = _context.sent;
|
|
47
|
+
options.onChange(page, {
|
|
48
|
+
page: matchedPage
|
|
49
|
+
});
|
|
50
|
+
_context.next = 16;
|
|
51
|
+
break;
|
|
52
|
+
|
|
53
|
+
case 13:
|
|
54
|
+
console.warn('Not match any route!'); // 兜底 404 页面
|
|
55
|
+
|
|
56
|
+
NotFound = function () {
|
|
57
|
+
return /*#__PURE__*/React.createElement('div', null, 'Page Not Found');
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
options.onChange(NotFound, {
|
|
61
|
+
page: {
|
|
62
|
+
id: pathname,
|
|
63
|
+
pathname: pathname,
|
|
64
|
+
route: '*',
|
|
65
|
+
path: '*',
|
|
66
|
+
config: {},
|
|
67
|
+
params: {},
|
|
68
|
+
component: function component() {
|
|
69
|
+
return Promise.resolve(NotFound);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
case 16:
|
|
75
|
+
case "end":
|
|
76
|
+
return _context.stop();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, _callee);
|
|
80
|
+
}));
|
|
81
|
+
|
|
82
|
+
return function () {
|
|
83
|
+
return _ref.apply(this, arguments);
|
|
84
|
+
};
|
|
85
|
+
}());
|
|
86
|
+
return history;
|
|
87
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MatchedPage, PageComponent, Pages, Routes, TabBar } from '@ray-js/types';
|
|
2
|
+
import { Router } from './Router';
|
|
3
|
+
declare const router: Router;
|
|
4
|
+
export declare function createRouter(options: {
|
|
5
|
+
routes: Routes;
|
|
6
|
+
pages: Pages;
|
|
7
|
+
tabBar: TabBar;
|
|
8
|
+
basename?: string;
|
|
9
|
+
onChange: (component: PageComponent, params: {
|
|
10
|
+
page: MatchedPage;
|
|
11
|
+
}) => void;
|
|
12
|
+
}): Router;
|
|
13
|
+
export default router;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
+
import "core-js/modules/es.string.search.js";
|
|
3
|
+
import "core-js/modules/es.string.replace.js";
|
|
4
|
+
import { createHistory } from './history';
|
|
5
|
+
import { Router } from './Router';
|
|
6
|
+
import { RouterScheduler } from './RouterScheduler';
|
|
7
|
+
var scheduler = window.__ray__routerScheduler__ = new RouterScheduler();
|
|
8
|
+
var router = window.__ray__router__ = new Router({
|
|
9
|
+
scheduler: scheduler
|
|
10
|
+
});
|
|
11
|
+
export function createRouter(options) {
|
|
12
|
+
var basename = options.basename,
|
|
13
|
+
_onChange = options.onChange,
|
|
14
|
+
routes = options.routes,
|
|
15
|
+
tabBar = options.tabBar,
|
|
16
|
+
pages = options.pages;
|
|
17
|
+
var history = createHistory({
|
|
18
|
+
basename: basename,
|
|
19
|
+
scheduler: scheduler,
|
|
20
|
+
onChange: function onChange() {
|
|
21
|
+
router.$href = window.location.href;
|
|
22
|
+
|
|
23
|
+
_onChange.apply(void 0, arguments);
|
|
24
|
+
}
|
|
25
|
+
}); // 设置路由基准路径
|
|
26
|
+
|
|
27
|
+
if (basename) {
|
|
28
|
+
router.scheduler.basename = basename;
|
|
29
|
+
} // 调度器注册页面
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
router.scheduler.registryPages({
|
|
33
|
+
routes: routes,
|
|
34
|
+
tabBar: tabBar,
|
|
35
|
+
pages: pages
|
|
36
|
+
});
|
|
37
|
+
var _history$location = history.location,
|
|
38
|
+
pathname = _history$location.pathname,
|
|
39
|
+
search = _history$location.search,
|
|
40
|
+
hash = _history$location.hash; // 首次触发 history change
|
|
41
|
+
|
|
42
|
+
history.replace(pathname + search + hash);
|
|
43
|
+
return router;
|
|
44
|
+
}
|
|
45
|
+
export default router;
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ray-js/router",
|
|
3
|
+
"version": "0.3.0-beta.1c347991",
|
|
4
|
+
"description": "Ray Core",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ray"
|
|
7
|
+
],
|
|
8
|
+
"author": "子长 <zichang.nong@tuya.com>",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"main": "lib/index.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"lib"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"clean": "rm -rf lib",
|
|
20
|
+
"build": "ray build --type=component --transform-mode=pure",
|
|
21
|
+
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@ray-js/library": "^0.3.0-beta.1c347991",
|
|
25
|
+
"@ray-js/types": "^0.3.0-beta.1c347991",
|
|
26
|
+
"history": "4.x",
|
|
27
|
+
"path-to-regexp": "^6.2.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@ray-js/cli": "^0.3.0-beta.1c347991",
|
|
31
|
+
"@types/history": "^4.7.9"
|
|
32
|
+
},
|
|
33
|
+
"maintainers": [
|
|
34
|
+
{
|
|
35
|
+
"name": "tuyafe",
|
|
36
|
+
"email": "tuyafe@tuya.com"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"gitHead": "e0bd013022ddda63380d3c9e20fd8cadb46cd61f",
|
|
40
|
+
"repository": {}
|
|
41
|
+
}
|