From 86a1216bfef40e97ece5e6f48577be0a90075f4f Mon Sep 17 00:00:00 2001 From: Qiyu8 Date: Sat, 21 Sep 2019 16:18:06 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix4375=20=E8=A7=A3=E5=86=B3=E5=BF=AB?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=AD=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?API=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9B=B8=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-quickapp/src/api/router/index.js | 11 ++++++++--- packages/taro-quickapp/src/create-component.js | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/taro-quickapp/src/api/router/index.js b/packages/taro-quickapp/src/api/router/index.js index 3cbde6cffaa9..f48fbd843319 100644 --- a/packages/taro-quickapp/src/api/router/index.js +++ b/packages/taro-quickapp/src/api/router/index.js @@ -1,5 +1,5 @@ import router from '@system.router' - +import * as path from 'path' import appGlobal from '../../global' import { addLeadingSlash, getUniqueKey } from '../../util' import { cacheDataGet, cacheDataSet } from '../../data-cache' @@ -47,7 +47,12 @@ function qappNavigate (options = {}, method = 'push') { } params = getUrlParams(url) const markIndex = url.indexOf('?') - const parseUrl = addLeadingSlash(url.substr(0, markIndex >= 0 ? markIndex : url.length)) + const componentPath = appGlobal.componentPath || '' + const parseUrl = url.substr(0, markIndex >= 0 ? markIndex : url.length).replace(/^(.\/)/g, '') + if (componentPath && /^(..\/)/g.test(parseUrl)) { + parseUrl = path.join(componentPath, parseUrl) + } + parseUrl = addLeadingSlash(parseUrl) appGlobal.taroRouterParamsCache = appGlobal.taroRouterParamsCache || {} appGlobal.taroRouterParamsCache[parseUrl] = params @@ -65,7 +70,7 @@ function qappNavigate (options = {}, method = 'push') { } try { router[method]({ - uri: url.substr(0, url.lastIndexOf('/')), + uri: parseUrl.substr(0, parseUrl.lastIndexOf('/')), params }) success && success(res) diff --git a/packages/taro-quickapp/src/create-component.js b/packages/taro-quickapp/src/create-component.js index 2a638ed07249..a5ac3b57f860 100644 --- a/packages/taro-quickapp/src/create-component.js +++ b/packages/taro-quickapp/src/create-component.js @@ -383,6 +383,7 @@ export default function createComponent (ComponentClass, isPage) { } } }) + appGlobal.componentPath = isPage addLeadingSlash(isPage) && cacheDataSet(addLeadingSlash(isPage), ComponentClass) } bindStaticFns(componentConf, ComponentClass) From 0bb3e6a4a1ac0549ea1678fce061a55a65c33419 Mon Sep 17 00:00:00 2001 From: Qiyu8 Date: Mon, 23 Sep 2019 15:07:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix4375=20=E8=A7=A3=E5=86=B3=E5=BF=AB?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B8=AD=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?API=E4=B8=8D=E6=94=AF=E6=8C=81=E7=9B=B8=E5=AF=B9=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-quickapp/src/api/router/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/taro-quickapp/src/api/router/index.js b/packages/taro-quickapp/src/api/router/index.js index f48fbd843319..ab55ca601b58 100644 --- a/packages/taro-quickapp/src/api/router/index.js +++ b/packages/taro-quickapp/src/api/router/index.js @@ -1,5 +1,4 @@ import router from '@system.router' -import * as path from 'path' import appGlobal from '../../global' import { addLeadingSlash, getUniqueKey } from '../../util' import { cacheDataGet, cacheDataSet } from '../../data-cache' @@ -48,9 +47,19 @@ function qappNavigate (options = {}, method = 'push') { params = getUrlParams(url) const markIndex = url.indexOf('?') const componentPath = appGlobal.componentPath || '' - const parseUrl = url.substr(0, markIndex >= 0 ? markIndex : url.length).replace(/^(.\/)/g, '') - if (componentPath && /^(..\/)/g.test(parseUrl)) { - parseUrl = path.join(componentPath, parseUrl) + let parseUrl = url.substr(0, markIndex >= 0 ? markIndex : url.length) + const RelativeReg = /\.\.\//g + if (componentPath && RelativeReg.test(parseUrl)) { + //当前页面路径最后一级是文件,在计算路径时去除 + var componentRootDir = componentPath.substr(0, componentPath.lastIndexOf('/')) + var pathArr = parseUrl.split('/') + //计算..出现的次数,每出现一次就往上一层 + for(let path of pathArr) { + if (path === '..') { + componentRootDir = componentRootDir.substr(0, componentRootDir.lastIndexOf('/')) + } + } + parseUrl = componentRootDir + '/' + parseUrl.replace(RelativeReg, '') } parseUrl = addLeadingSlash(parseUrl) appGlobal.taroRouterParamsCache = appGlobal.taroRouterParamsCache || {}