# Navigation ## 导航和路由 在 UniApp 中使用 uView UI 组件进行页面导航和路由管理。 ### 使用 UniApp 导航 API #### 页面跳转 ```javascript // 保留当前页面,跳转到应用内的某个页面 uni.navigateTo({ url: '/pages/detail/detail?id=1' }) // 关闭当前页面,跳转到应用内的某个页面 uni.redirectTo({ url: '/pages/login/login' }) // 跳转到 tabBar 页面 uni.switchTab({ url: '/pages/index/index' }) // 返回上一页面 uni.navigateBack({ delta: 1 }) ``` #### 使用 uView 按钮进行跳转 ```vue ``` ### 使用 uView 导航栏 #### 自定义导航栏 ```json { "pages": [ { "path": "pages/index/index", "style": { "navigationStyle": "custom" } } ] } ``` 页面中使用 uView 导航栏: ```vue ``` ### 使用 uView 返回顶部 ```vue ``` ### TabBar 导航 #### 使用原生 TabBar ```json { "tabBar": { "color": "#7A7E83", "selectedColor": "#409EFF", "borderStyle": "black", "backgroundColor": "#ffffff", "list": [ { "pagePath": "pages/index/index", "text": "首页" }, { "pagePath": "pages/user/user", "text": "我的" } ] } } ``` #### 使用 uView TabBar 组件 ```vue ``` ### 页面传参 #### 传递参数 ```javascript // 跳转并传递参数 uni.navigateTo({ url: '/pages/detail/detail?id=1&name=test' }) ``` #### 接收参数 ```vue ``` ### 使用 uView 搜索框导航 ```vue ``` ### 导航栏返回按钮自定义 ```vue ``` ## 注意事项 1. **路径格式**:路径必须以 `/` 开头 2. **TabBar 跳转**:使用 `uni.switchTab` 跳转到 tabBar 页面 3. **参数传递**:URL 参数需要编码 4. **页面栈**:注意页面栈限制(最多 10 层) 5. **返回按钮**:自定义导航栏需要自己处理返回逻辑