From b3c1d414ac22f1bce22894004c3e724f7d3c9d4e Mon Sep 17 00:00:00 2001 From: ambit-tsai <42671189+ambit-tsai@users.noreply.github.com> Date: Wed, 3 Oct 2018 23:39:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8F=90=E9=AB=98getLocation=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E7=9A=84ie8=E5=85=BC=E5=AE=B9=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getLocation函数内容转义后为`return Object.assign({}, source.location, {/*略*/});`。 当使用babel-polyfill提供Object.assign语法支持时,会报错:`Object.prototype.propertyIsEnumerable: 'this' 不是 JavaScript 对象`。 使用for循环替换Object.assign进行属性复制。 --- packages/router/history.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/router/history.js b/packages/router/history.js index 20744b621..890e2aad6 100644 --- a/packages/router/history.js +++ b/packages/router/history.js @@ -5,14 +5,19 @@ import { export var modeObject = {} //伪造一个Location对象 function getLocation(source) { - return { - ...source.location, + const location = { getPath() { return modeObject.value === "hash" ? this.hash.slice(1) : this.pathname }, state: source.history.state, key: (source.history.state && source.history.state.key) || "initial" }; + for (const key in source.location) { + if (!Object.hasOwnProperty.call(source.location, key)) { + location[key] = source.location[key]; + } + } + return location; } //伪造一个History对象 @@ -175,4 +180,4 @@ export { navigate, createHistory, createMemorySource -}; \ No newline at end of file +}; From 664dcd721af3a69c47571aace6cfe3e66189fb90 Mon Sep 17 00:00:00 2001 From: ambit-tsai <42671189+ambit-tsai@users.noreply.github.com> Date: Thu, 4 Oct 2018 12:39:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?getLocation=E4=B8=ADfor=E7=9A=84if=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=9D=A1=E4=BB=B6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 判断条件写反了,去掉`!` --- packages/router/history.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/router/history.js b/packages/router/history.js index 890e2aad6..420818906 100644 --- a/packages/router/history.js +++ b/packages/router/history.js @@ -13,7 +13,7 @@ function getLocation(source) { key: (source.history.state && source.history.state.key) || "initial" }; for (const key in source.location) { - if (!Object.hasOwnProperty.call(source.location, key)) { + if (Object.prototype.hasOwnProperty.call(source.location, key)) { location[key] = source.location[key]; } }