路由跳转
基本用法
需要在 main.js 中开启路由功能,具体参考全局配置
javascript
// 不携带参数
uni.$fu.$openPage('index')
// 带参数
uni.$fu.$openPage({name: 'index', query: { id: 1 }})跳转类型
- 通过
type属性指定跳转类型,可选值有navigateTo、redirectTo、switchTab、reLaunch
javascript
uni.$fu.$openPage({name: 'index', type: 'switchTab'})- 也可以通过
pages.json直接指定
json
{
"pages": [
{ "name": "index", "type": "switchTab", "path": "pages/index/index" }
]
...
}跳转携带参数
通过 query 属性携带参数
javascript
uni.$fu.$openPage({name: 'detail', query: { id: 1 }})获取携带参数
通过目标页面的 onLoad 生命周期函数中获取参数
注意
因为 $openPage 方法跳转携带参数是通过 encodeURIComponent 编码的,所以获取参数时需要先用 decodeURIComponent 解码。
因此 fusions-ui 提供了 $parseURL 方法来解码参数。
javascript
// #ifndef VUE3
<script>
export default {
onLoad(options) {
const query = uni.$fu.$parseURL(options.query)
}
}
</script>
// #endif
// #ifdef VUE3
<script setup>
import { onLoad } from '@dcloudio/uni-app';
onLoad((options) => {
const query = uni.$fu.$parseURL(options.query)
});
</script>
// #endif