@bpui/libs
Advanced tools
Comparing version 0.2.10 to 0.2.11
@@ -5,3 +5,3 @@ { | ||
"@types/hammerjs": "^2.0.36", | ||
"febs-browser": "^1.0.3", | ||
"febs-browser": "^1.0.4", | ||
"hammerjs": "^2.0.8", | ||
@@ -53,3 +53,3 @@ "smoothscroll-polyfill": "^0.4.4" | ||
"name": "@bpui/libs", | ||
"version": "0.2.10" | ||
"version": "0.2.11" | ||
} |
@@ -24,2 +24,5 @@ 'use strict'; | ||
constructor() { | ||
} | ||
/** | ||
@@ -52,3 +55,8 @@ * 历史记录长度. | ||
return {path: path, query: query, state: window.history.state? febs.utils.mergeMap(window.history.state): null}; | ||
return { | ||
path: path, | ||
query: query, | ||
state: window.history.state ? febs.utils.mergeMap(window.history.state) : null, | ||
hash: window.location.hash | ||
}; | ||
} | ||
@@ -65,4 +73,14 @@ | ||
else { | ||
l = path; | ||
l = febs.utils.mergeMap(path); | ||
} | ||
let hi = l.path.indexOf('#'); | ||
if (hi >= 0) { | ||
let hash = l.path.substring(hi); | ||
l.path = l.path.substring(0, hi); | ||
if (hash.length == 1) { | ||
hash = null; | ||
} | ||
l.hash = hash; | ||
} | ||
@@ -73,6 +91,19 @@ let srcPath = l.path; | ||
// hash. | ||
if (!febs.string.isEmpty(l.hash)) { | ||
if (l.hash[0] != '#' && l.path[l.path.length-1] != '#') { | ||
l.path += '#'; | ||
} | ||
l.path += l.hash; | ||
} | ||
window.history.pushState(l.state, null, l.path); | ||
if (trigger) { | ||
let location = {path: srcPath, query: l.query, state: l.state}; | ||
let location = { | ||
path: srcPath, | ||
query: l.query, | ||
state: l.state, | ||
hash: l.hash, | ||
}; | ||
setTimeout(()=>{ | ||
@@ -90,5 +121,15 @@ this._triggerRouteChanged(location, null); | ||
else { | ||
l = path; | ||
l = febs.utils.mergeMap(path); | ||
} | ||
let hi = l.path.indexOf('#'); | ||
if (hi >= 0) { | ||
let hash = l.path.substring(hi); | ||
l.path = l.path.substring(0, hi); | ||
if (hash.length == 1) { | ||
hash = null; | ||
} | ||
l.hash = hash; | ||
} | ||
let srcPath = l.path; | ||
@@ -98,6 +139,19 @@ l.path = url.stringifyUrl(l.path, l.query); | ||
// hash. | ||
if (!febs.string.isEmpty(l.hash)) { | ||
if (l.hash[0] != '#' && l.path[l.path.length-1] != '#') { | ||
l.path += '#'; | ||
} | ||
l.path += l.hash; | ||
} | ||
window.history.replaceState(l.state, null, l.path); | ||
if (trigger) { | ||
let location = {path: srcPath, query: l.query, state: l.state}; | ||
let location = { | ||
path: srcPath, | ||
query: l.query, | ||
state: l.state, | ||
hash: l.hash, | ||
}; | ||
setTimeout(()=>{ | ||
@@ -144,3 +198,8 @@ this._triggerRouteChanged(location, 1); | ||
let query = url.parseUrl(window.location.search); | ||
let location = {path: utils.getCurrentRoutePath(this.basePath), query: febs.utils.mergeMap(query), state: history.state} | ||
let location = { | ||
path: utils.getCurrentRoutePath(this.basePath), | ||
query: febs.utils.mergeMap(query), | ||
state: history.state, | ||
hash: window.location.hash | ||
} | ||
this._triggerRouteChanged(location, null); | ||
@@ -166,3 +225,3 @@ }); | ||
private _triggerRouteChanged(location, type) { | ||
_triggerRouteChanged(location, type) { | ||
if (window[InstanceOnRoute]) { | ||
@@ -173,3 +232,8 @@ let listeners = window[InstanceOnRoute]; | ||
listeners[i]( | ||
{path: location.path, query: febs.utils.mergeMap(location.query), state: febs.utils.mergeMap(location.state)}, | ||
{ | ||
path: location.path, | ||
query: febs.utils.mergeMap(location.query), | ||
state: febs.utils.mergeMap(location.state), | ||
hash: location.hash, | ||
}, | ||
type); | ||
@@ -176,0 +240,0 @@ } |
@@ -11,4 +11,13 @@ /** | ||
type Directory<T> = { [key: string]: T }; | ||
type Location = {path: string, query?: Directory<string>, state?: Directory<any> }; | ||
type Location = { | ||
path: string, | ||
query?: Directory<string>, | ||
state?: Directory<any>, | ||
/** | ||
* It will container '#', if no empty. | ||
*/ | ||
hash?: string, | ||
}; | ||
/** | ||
@@ -15,0 +24,0 @@ * router接口. (仅需提供如下接口) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
2705413
24785
Updatedfebs-browser@^1.0.4