@viewfly/router 2.0.0 → 2.1.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/bundles/index.d.ts +2 -0
- package/bundles/index.esm.js +11 -2
- package/bundles/index.js +11 -2
- package/package.json +2 -2
package/bundles/index.d.ts
CHANGED
|
@@ -104,6 +104,8 @@ interface NavigatorHooks {
|
|
|
104
104
|
declare class BrowserNavigator extends Navigator {
|
|
105
105
|
private hooks;
|
|
106
106
|
onUrlChanged: Observable<void>;
|
|
107
|
+
/** 挂载在 location 上的路径前缀;'' 或 '/' 表示站点根,不做剥离 */
|
|
108
|
+
private get basePathPrefix();
|
|
107
109
|
get pathname(): string;
|
|
108
110
|
private urlParser;
|
|
109
111
|
urlTree: UrlTree;
|
package/bundles/index.esm.js
CHANGED
|
@@ -343,9 +343,18 @@ function formatQueryParams(queryParams) {
|
|
|
343
343
|
return params.join('&');
|
|
344
344
|
}
|
|
345
345
|
let BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
346
|
+
/** 挂载在 location 上的路径前缀;'' 或 '/' 表示站点根,不做剥离 */
|
|
347
|
+
get basePathPrefix() {
|
|
348
|
+
return this.baseUrl === '/' || this.baseUrl === '' ? '' : this.baseUrl;
|
|
349
|
+
}
|
|
346
350
|
get pathname() {
|
|
347
351
|
const pathname = location.pathname;
|
|
348
|
-
|
|
352
|
+
if (!this.basePathPrefix) {
|
|
353
|
+
return pathname;
|
|
354
|
+
}
|
|
355
|
+
return pathname.startsWith(this.basePathPrefix)
|
|
356
|
+
? pathname.substring(this.basePathPrefix.length)
|
|
357
|
+
: pathname;
|
|
349
358
|
}
|
|
350
359
|
constructor(baseUrl, hooks = {}) {
|
|
351
360
|
super(baseUrl);
|
|
@@ -390,7 +399,7 @@ let BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
|
390
399
|
this.urlTree = this.getUrlTree();
|
|
391
400
|
this.urlChangeEvent.next();
|
|
392
401
|
}));
|
|
393
|
-
if (
|
|
402
|
+
if (this.basePathPrefix && !location.pathname.startsWith(this.basePathPrefix)) {
|
|
394
403
|
history.replaceState(null, '', this.baseUrl);
|
|
395
404
|
}
|
|
396
405
|
}
|
package/bundles/index.js
CHANGED
|
@@ -345,9 +345,18 @@ function formatQueryParams(queryParams) {
|
|
|
345
345
|
return params.join('&');
|
|
346
346
|
}
|
|
347
347
|
exports.BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
348
|
+
/** 挂载在 location 上的路径前缀;'' 或 '/' 表示站点根,不做剥离 */
|
|
349
|
+
get basePathPrefix() {
|
|
350
|
+
return this.baseUrl === '/' || this.baseUrl === '' ? '' : this.baseUrl;
|
|
351
|
+
}
|
|
348
352
|
get pathname() {
|
|
349
353
|
const pathname = location.pathname;
|
|
350
|
-
|
|
354
|
+
if (!this.basePathPrefix) {
|
|
355
|
+
return pathname;
|
|
356
|
+
}
|
|
357
|
+
return pathname.startsWith(this.basePathPrefix)
|
|
358
|
+
? pathname.substring(this.basePathPrefix.length)
|
|
359
|
+
: pathname;
|
|
351
360
|
}
|
|
352
361
|
constructor(baseUrl, hooks = {}) {
|
|
353
362
|
super(baseUrl);
|
|
@@ -392,7 +401,7 @@ exports.BrowserNavigator = class BrowserNavigator extends Navigator {
|
|
|
392
401
|
this.urlTree = this.getUrlTree();
|
|
393
402
|
this.urlChangeEvent.next();
|
|
394
403
|
}));
|
|
395
|
-
if (
|
|
404
|
+
if (this.basePathPrefix && !location.pathname.startsWith(this.basePathPrefix)) {
|
|
396
405
|
history.replaceState(null, '', this.baseUrl);
|
|
397
406
|
}
|
|
398
407
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A routing library based on the Viewfly framework that can be run in the browser or Nodejs background.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@tanbo/stream": "^1.2.4",
|
|
18
|
-
"@viewfly/core": "^2.
|
|
18
|
+
"@viewfly/core": "^2.1.0",
|
|
19
19
|
"url": "^0.11.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|