Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
小浣熊撸代码
uni-app
提交
b93bf39a
U
uni-app
项目概览
小浣熊撸代码
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b93bf39a
编写于
4月 15, 2021
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: uni.redirectTo
上级
ced3159e
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
69 addition
and
21 deletion
+69
-21
packages/uni-h5/dist/uni-h5.esm.js
packages/uni-h5/dist/uni-h5.esm.js
+26
-6
packages/uni-h5/src/framework/components/page/index.ts
packages/uni-h5/src/framework/components/page/index.ts
+1
-1
packages/uni-h5/src/framework/components/page/pageHead.tsx
packages/uni-h5/src/framework/components/page/pageHead.tsx
+4
-3
packages/uni-h5/src/framework/plugin/page.ts
packages/uni-h5/src/framework/plugin/page.ts
+14
-5
packages/uni-h5/src/framework/plugin/provide/page.ts
packages/uni-h5/src/framework/plugin/provide/page.ts
+12
-0
packages/uni-h5/src/service/api/route/redirectTo.ts
packages/uni-h5/src/service/api/route/redirectTo.ts
+5
-2
packages/uni-h5/src/service/api/route/utils.ts
packages/uni-h5/src/service/api/route/utils.ts
+7
-4
未找到文件。
packages/uni-h5/dist/uni-h5.esm.js
浏览文件 @
b93bf39a
...
...
@@ -1101,6 +1101,12 @@ function normalizePageMeta(pageMeta) {
navigationBar
.
backButton
=
pageMeta
.
isQuit
?
false
:
true
;
navigationBar
.
titleColor
=
navigationBar
.
titleColor
||
"
#fff
"
;
navigationBar
.
backgroundColor
=
navigationBar
.
backgroundColor
||
"
#F7F7F7
"
;
if
(
__UNI_FEATURE_PAGES__
)
{
if
(
history
.
state
&&
history
.
state
.
__type__
===
"
redirectTo
"
&&
getCurrentPages
().
length
===
0
)
{
pageMeta
.
isEntry
=
true
;
pageMeta
.
isQuit
=
true
;
}
}
return
pageMeta
;
}
const
sheetsMap
=
new
Map
();
...
...
@@ -1154,7 +1160,7 @@ function getCurrentPages$1(isAll = false) {
pruneCurrentPages
();
return
[...
currentPagesMap
.
values
()];
}
function
removeCurrentPages
(
delta
=
-
1
)
{
function
removeCurrentPages
(
delta
=
1
,
removeRouteCaches
=
false
)
{
const
keys
=
[...
currentPagesMap
.
keys
()];
const
start
=
keys
.
length
-
1
;
const
end
=
start
-
delta
;
...
...
@@ -1164,6 +1170,13 @@ function removeCurrentPages(delta = -1) {
pageVm
.
$
.
__isUnload
=
true
;
invokeHook
(
pageVm
,
"
onUnload
"
);
currentPagesMap
.
delete
(
routeKey
);
if
(
removeRouteCaches
)
{
const
vnode
=
pageCacheMap
.
get
(
routeKey
);
if
(
vnode
)
{
pageCacheMap
.
delete
(
routeKey
);
routeCache
.
pruneCacheEntry
(
vnode
);
}
}
}
}
let
id
=
history
.
state
&&
history
.
state
.
__id__
||
1
;
...
...
@@ -11281,7 +11294,10 @@ function navigate(type, url) {
});
}
const
navigateTo
=
defineAsyncApi
(
API_NAVIGATE_TO
,
({
url
},
{
resolve
,
reject
})
=>
navigate
(
API_NAVIGATE_TO
,
url
).
then
(
resolve
).
catch
(
reject
),
NavigateToProtocol
,
NavigateToOptions
);
const
redirectTo
=
defineAsyncApi
(
API_REDIRECT_TO
,
({
url
},
{
resolve
,
reject
})
=>
navigate
(
API_REDIRECT_TO
,
url
).
then
(
resolve
).
catch
(
reject
),
RedirectToProtocol
,
RedirectToOptions
);
const
redirectTo
=
defineAsyncApi
(
API_REDIRECT_TO
,
({
url
},
{
resolve
,
reject
})
=>
{
removeCurrentPages
(
1
,
true
);
return
navigate
(
API_REDIRECT_TO
,
url
).
then
(
resolve
).
catch
(
reject
);
},
RedirectToProtocol
,
RedirectToOptions
);
const
reLaunch
=
defineAsyncApi
(
API_RE_LAUNCH
,
({
url
},
{
resolve
,
reject
})
=>
navigate
(
API_RE_LAUNCH
,
url
).
then
(
resolve
).
catch
(
reject
),
ReLaunchProtocol
,
ReLaunchOptions
);
const
switchTab
=
defineAsyncApi
(
API_SWITCH_TAB
,
({
url
},
{
resolve
,
reject
})
=>
navigate
(
API_SWITCH_TAB
,
url
).
then
(
resolve
).
catch
(
reject
),
SwitchTabProtocol
,
SwitchTabOptions
);
function
setNavigationBar
(
pageMeta
,
type
,
args
,
resolve
,
reject
)
{
...
...
@@ -11958,7 +11974,7 @@ var PageHead = /* @__PURE__ */ defineComponent({
const
searchInput
=
__UNI_FEATURE_NAVIGATIONBAR_SEARCHINPUT__
&&
usePageHeadSearchInput
();
__UNI_FEATURE_NAVIGATIONBAR_TRANSPARENT__
&&
usePageHeadTransparent
(
headRef
,
navigationBar
);
return
()
=>
{
const
backButtonTsx
=
__UNI_FEATURE_PAGES__
?
createBackButtonTsx
(
navigationBar
)
:
null
;
const
backButtonTsx
=
__UNI_FEATURE_PAGES__
?
createBackButtonTsx
(
pageMeta
)
:
null
;
const
leftButtonsTsx
=
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
?
createButtonsTsx
(
buttons
.
left
)
:
[];
const
rightButtonsTsx
=
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
?
createButtonsTsx
(
buttons
.
right
)
:
[];
const
type
=
navigationBar
.
type
||
"
default
"
;
...
...
@@ -11982,8 +11998,12 @@ var PageHead = /* @__PURE__ */ defineComponent({
};
}
});
function
createBackButtonTsx
(
navigationBar
)
{
if
(
navigationBar
.
backButton
)
{
function
createBackButtonTsx
(
pageMeta
)
{
const
{
navigationBar
,
isQuit
}
=
pageMeta
;
if
(
navigationBar
.
backButton
&&
!
isQuit
)
{
return
createVNode
(
"
div
"
,
{
class
:
"
uni-page-head-btn
"
,
onClick
:
onPageHeadBackButton
...
...
@@ -12487,7 +12507,7 @@ function createPageRefreshTsx(refreshRef, pageMeta) {
}
var
index
=
defineComponent
({
name
:
"
Page
"
,
setup
(
props
,
ctx
)
{
setup
(
_
props
,
ctx
)
{
const
{
navigationBar
}
=
providePageMeta
();
return
()
=>
createVNode
(
"
uni-page
"
,
null
,
__UNI_FEATURE_NAVIGATIONBAR__
&&
navigationBar
.
style
!==
"
custom
"
?
[
createVNode
(
PageHead
),
createPageBodyVNode
(
ctx
)]
:
[
createPageBodyVNode
(
ctx
)]);
}
...
...
packages/uni-h5/src/framework/components/page/index.ts
浏览文件 @
b93bf39a
...
...
@@ -14,7 +14,7 @@ import { providePageMeta } from '../../plugin/provide'
export
default
defineComponent
({
name
:
'
Page
'
,
setup
(
props
,
ctx
)
{
setup
(
_
props
,
ctx
)
{
const
{
navigationBar
}
=
providePageMeta
()
return
()
=>
createVNode
(
...
...
packages/uni-h5/src/framework/components/page/pageHead.tsx
浏览文件 @
b93bf39a
...
...
@@ -48,7 +48,7 @@ export default /*#__PURE__*/ defineComponent({
return
()
=>
{
// 单页面无需back按钮
const
backButtonTsx
=
__UNI_FEATURE_PAGES__
?
createBackButtonTsx
(
navigationBar
)
?
createBackButtonTsx
(
pageMeta
)
:
null
const
leftButtonsTsx
=
__UNI_FEATURE_NAVIGATIONBAR_BUTTONS__
?
createButtonsTsx
(
buttons
.
left
)
...
...
@@ -82,8 +82,9 @@ export default /*#__PURE__*/ defineComponent({
},
})
function
createBackButtonTsx
(
navigationBar
:
UniApp
.
PageNavigationBar
)
{
if
(
navigationBar
.
backButton
)
{
function
createBackButtonTsx
(
pageMeta
:
UniApp
.
PageRouteMeta
)
{
const
{
navigationBar
,
isQuit
}
=
pageMeta
if
(
navigationBar
.
backButton
&&
!
isQuit
)
{
return
(
<
div
class
=
"uni-page-head-btn"
onClick
=
{
onPageHeadBackButton
}
>
{
createSvgIconVNode
(
...
...
packages/uni-h5/src/framework/plugin/page.ts
浏览文件 @
b93bf39a
...
...
@@ -9,6 +9,7 @@ import { useRoute, RouteLocationNormalizedLoaded } from 'vue-router'
import
{
invokeHook
}
from
'
@dcloudio/uni-core
'
import
{
removeLeadingSlash
}
from
'
@dcloudio/uni-shared
'
import
{
usePageMeta
}
from
'
./provide
'
import
{
NavigateType
}
from
'
../../service/api/route/utils
'
const
SEP
=
'
$$
'
...
...
@@ -23,11 +24,14 @@ function pruneCurrentPages() {
}
export
function
getCurrentPages
(
isAll
:
boolean
=
false
)
{
pruneCurrentPages
()
// TODO 目前页面unmounted时机较晚,前一个页面onShow里边调用getCurrentPages,可能还会获取到上一个准备被销毁的页面
pruneCurrentPages
()
return
[...
currentPagesMap
.
values
()]
}
export
function
removeCurrentPages
(
delta
:
number
=
-
1
)
{
export
function
removeCurrentPages
(
delta
:
number
=
1
,
removeRouteCaches
=
false
)
{
const
keys
=
[...
currentPagesMap
.
keys
()]
const
start
=
keys
.
length
-
1
const
end
=
start
-
delta
...
...
@@ -37,14 +41,19 @@ export function removeCurrentPages(delta: number = -1) {
pageVm
.
$
.
__isUnload
=
true
invokeHook
(
pageVm
,
'
onUnload
'
)
currentPagesMap
.
delete
(
routeKey
)
if
(
removeRouteCaches
)
{
const
vnode
=
pageCacheMap
.
get
(
routeKey
)
if
(
vnode
)
{
pageCacheMap
.
delete
(
routeKey
)
routeCache
.
pruneCacheEntry
!
(
vnode
)
}
}
}
}
let
id
=
(
history
.
state
&&
history
.
state
.
__id__
)
||
1
export
function
createPageState
(
type
:
'
navigateTo
'
|
'
redirectTo
'
|
'
reLaunch
'
|
'
switchTab
'
)
{
export
function
createPageState
(
type
:
NavigateType
)
{
return
{
__id__
:
++
id
,
__type__
:
type
,
...
...
packages/uni-h5/src/framework/plugin/provide/page.ts
浏览文件 @
b93bf39a
...
...
@@ -80,5 +80,17 @@ function normalizePageMeta(pageMeta: UniApp.PageRouteMeta) {
navigationBar
.
backButton
=
pageMeta
.
isQuit
?
false
:
true
navigationBar
.
titleColor
=
navigationBar
.
titleColor
||
'
#fff
'
navigationBar
.
backgroundColor
=
navigationBar
.
backgroundColor
||
'
#F7F7F7
'
if
(
__UNI_FEATURE_PAGES__
)
{
// 首页执行了redirectTo
if
(
history
.
state
&&
history
.
state
.
__type__
===
'
redirectTo
'
&&
getCurrentPages
().
length
===
0
)
{
pageMeta
.
isEntry
=
true
pageMeta
.
isQuit
=
true
}
}
return
pageMeta
}
packages/uni-h5/src/service/api/route/redirectTo.ts
浏览文件 @
b93bf39a
...
...
@@ -5,12 +5,15 @@ import {
RedirectToOptions
,
RedirectToProtocol
,
}
from
'
@dcloudio/uni-api
'
import
{
removeCurrentPages
}
from
'
../../../framework/plugin/page
'
import
{
navigate
}
from
'
./utils
'
export
const
redirectTo
=
defineAsyncApi
<
API_TYPE_REDIRECT_TO
>
(
API_REDIRECT_TO
,
({
url
},
{
resolve
,
reject
})
=>
navigate
(
API_REDIRECT_TO
,
url
).
then
(
resolve
).
catch
(
reject
),
({
url
},
{
resolve
,
reject
})
=>
{
removeCurrentPages
(
1
,
true
)
return
navigate
(
API_REDIRECT_TO
,
url
).
then
(
resolve
).
catch
(
reject
)
},
RedirectToProtocol
,
RedirectToOptions
)
packages/uni-h5/src/service/api/route/utils.ts
浏览文件 @
b93bf39a
import
{
isNavigationFailure
,
Router
}
from
'
vue-router
'
import
{
createPageState
}
from
'
../../../framework/plugin/page
'
export
function
navigate
(
type
:
'
navigateTo
'
|
'
redirectTo
'
|
'
reLaunch
'
|
'
switchTab
'
,
url
:
string
):
Promise
<
undefined
>
{
export
type
NavigateType
=
|
'
navigateTo
'
|
'
redirectTo
'
|
'
reLaunch
'
|
'
switchTab
'
export
function
navigate
(
type
:
NavigateType
,
url
:
string
):
Promise
<
undefined
>
{
const
router
=
getApp
().
$router
as
Router
return
new
Promise
((
resolve
,
reject
)
=>
{
router
[
type
===
'
navigateTo
'
?
'
push
'
:
'
replace
'
]({
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录