Skip to content

Commit

Permalink
fix4375 解决快应用中路由跳转API不支持相对路径的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiyu8 authored and ZakaryCode committed Mar 26, 2020
1 parent 6204995 commit de01a70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/taro-quickapp/src/api/router/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/taro-quickapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export default function createComponent (ComponentClass, isPage) {
}
}
})
appGlobal.componentPath = isPage
addLeadingSlash(isPage) && cacheDataSet(addLeadingSlash(isPage), ComponentClass)
}
bindStaticFns(componentConf, ComponentClass)
Expand Down

0 comments on commit de01a70

Please sign in to comment.