Declarative navigation of uni-app, programmatic navigation

Declarative Navigation for uni-app

Declarative navigation jump of uni-app

Jump to normal page

		<navigator url="../detail/detail">跳转到详情</navigator>
		<navigator url="../test/test">跳转到test</navigator>

Jump to the tabbar page

  • Need to add this property:open-type="switchTab"
		<navigator url="../index/index" open-type="switchTab">跳转到首页</navigator>
		<navigator url="../about/about" open-type="switchTab">跳转到about</navigator>

open-type related values

redirect

  • redirect
    • It is to close the current page (the page has been uninstalled), and then jump to the page set by the url, there is no previous page record
<navigator url="../detail/detail" open-type="redirect">跳转到详情</navigator>
  • Effect
    insert image description here

Declarative navigation parameters of uni-app

url method passing parameters

<template>
	<view>
			<navigator url="../detail/detail?id=100&name=pink">跳转到详情</navigator>
<!-- 		<button @click="goDetail">跳转到详情</button>
		<button type="default" @click="goDetail2">跳转到详情</button> -->
	</view>
</template>

<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
		},
	}
</script>
  • Effect
    insert image description here

The page gets the passed parameter data

<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
	</view>
</template>
<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
		},
		onLoad(options){
    
    
			console.log("页面加载 options",options);
		}
	}
</script>
  • Effect
    insert image description here

Programmatic navigation of uni-app

Programmatic navigation jump of uni-app

uni.navigateTo(OBJECT)

  • Keep the current page, jump to a page in the app, and use uni.navigateBack to return to the original page.
<template>
	<view>
		<button @click="goDetail">跳转到详情</button>
	</view>
</template>

<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
			goDetail(){
    
    
				uni.navigateTo({
    
    
					url:"../detail/detail",
					animationType: 'pop-in',
				})
			},
		},
	}
</script>
  • Effect
    • Jump to the details page

uni.switchTab(OBJECT)

  • Jump to the tabBar page and close all other non-tabBar pages
<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
		<button type="default" @click="goAbout">跳转到about</button>
	</view>
</template>
<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
			goAbout(){
    
    
				uni.switchTab({
    
    
					url:"../about/about",
				})
			},
		},
		onUnload(){
    
    
			console.log("详情页 卸载");
		}
	}
</script>
  • Effect
  • From the details page, click to jump to about, because about is the page of the tabbar component, but the details page is not a tabbar, all non-tabbar pages will be uninstalled

uni.redirectTo(OBJECT)

  • Close the current page and jump to a page in the app.
<template>
	<view>
		<button type="default" @click="goDetail2">跳转到详情</button>
	</view>
</template>

<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
			goDetail2(){
    
    
				uni.redirectTo({
    
    
					url:"../detail/detail",
				})
			}
		},
		onUnload(){
    
    
			console.log("msg 卸载");
		}
	}
</script>
  • Effect
    • When jumping to the details page, the current msg page will be closed, that is, unloaded, and the onUnload function will be triggered

Programmatic navigation parameters

The current page, jump to the next page, pass the parameter value

<template>
	<view>
 		<button @click="goDetail">跳转到详情</button>
	</view>
</template>

<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
			goDetail(){
    
    
				uni.navigateTo({
    
    
					url:"../detail/detail?id=10&name=ppp"
				})
			}
		},
	}
</script>
  • Effect
    insert image description here

After jumping to the page, get the passed parameters

<template>
	<view>
		<view class="box3">
			我是box3 详情
		</view>
	</view>
</template>
<script>
	export default {
    
    
		data(){
    
    
			return {
    
    
			}
		},	
		methods: {
    
    
		},
		onLoad(options){
    
    
			console.log("页面加载-options", options);
		}
	}
</script>
  • Effect
    insert image description here

Guess you like

Origin blog.csdn.net/weixin_43845137/article/details/124026774