File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -425,3 +425,24 @@ export function assertParentChild(
425
425
}
426
426
return false
427
427
}
428
+
429
+ export function resolveAbsolutePath (
430
+ path :string ,
431
+ router :Router
432
+ ) :string | never {
433
+ const reg = / ^ \/ ? ( [ ^ \? ] + ) ( \? .+ ) ? / ;
434
+ if ( ! reg . test ( path ) ) {
435
+ throw new Error ( `${ path } 路径错误,请提供完整的路径(10001)。` ) ;
436
+ }
437
+ const paramsArray = path . match ( reg ) ;
438
+ if ( paramsArray == null ) {
439
+ throw new Error ( `${ path } 路径错误,请提供完整的路径(10002)。` ) ;
440
+ }
441
+ const relative = paramsArray [ 1 ] . replace ( / \/ / g, `\\/` ) . replace ( / \. \. / g, `[^\\/]+` ) ;
442
+ const relativeReg = new RegExp ( `^\\/${ relative } $` ) ;
443
+ const route = router . options . routes . filter ( it => relativeReg . test ( it . path ) ) ;
444
+ if ( route . length !== 1 ) {
445
+ throw new Error ( `${ path } 路径错误,尝试转成绝对路径失败,请手动转成绝对路径(10003)。` ) ;
446
+ }
447
+ return route [ 0 ] . path + paramsArray [ 2 ] ;
448
+ }
Original file line number Diff line number Diff line change @@ -14,7 +14,8 @@ import {
14
14
routesForMapRoute ,
15
15
getRoutePath ,
16
16
getDataType ,
17
- notDeepClearNull
17
+ notDeepClearNull ,
18
+ resolveAbsolutePath
18
19
} from '../helpers/utils'
19
20
20
21
import {
@@ -98,11 +99,9 @@ function callRouterMethod(
98
99
const routerMethodName = rewriteMethodToggle [ ( funName as reNavMethodRule ) ]
99
100
let path = ( option as uniNavApiRule ) . url ;
100
101
if ( ! path . startsWith ( '/' ) ) {
101
- warn (
102
- `uni-app 原生方法被重写时,只能使用绝对路径进行跳转。${ JSON . stringify ( option ) } ` ,
103
- router ,
104
- true
105
- ) ;
102
+ const absolutePath = resolveAbsolutePath ( path , router ) ;
103
+ path = absolutePath ;
104
+ ( option as uniNavApiRule ) . url = absolutePath ;
106
105
}
107
106
if ( funName === 'switchTab' ) {
108
107
const route = routesForMapRoute ( router , path , [ 'pathMap' , 'finallyPathList' ] )
You can’t perform that action at this time.
0 commit comments