欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

react路由跳轉(zhuǎn)的方式有哪些

這篇文章主要介紹“react路由跳轉(zhuǎn)的方式有哪些”的相關(guān)知識(shí),小編通過實(shí)際案例向大家展示操作過程,操作方法簡單快捷,實(shí)用性強(qiáng),希望這篇“react路由跳轉(zhuǎn)的方式有哪些”文章能幫助大家解決問題。

成都創(chuàng)新互聯(lián)公司是專業(yè)的沾化網(wǎng)站建設(shè)公司,沾化接單;提供成都網(wǎng)站建設(shè)、網(wǎng)站制作,網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行沾化網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!

方式:1、利用params,參數(shù)會(huì)顯示在地址欄,語法“...({pathname:...,search:地址欄數(shù)據(jù)})”;2、利用state,地址欄看不到數(shù)據(jù),語法“...({pathname:...,state:{test:...}}”。

本教程操作環(huán)境:Windows10系統(tǒng)、react17.0.1版、Dell G3電腦。

react路由跳轉(zhuǎn)的幾種方式是什么

注意: 這里使用的react-router-dom是版本5以上,路由形式是history模式
react-router-dom文檔地址,其中依賴包history的github地址

1. params形式,路由跳轉(zhuǎn)后,參數(shù)會(huì)顯示在地址欄

react路由跳轉(zhuǎn)的方式有哪些

  • 跳轉(zhuǎn)的方法是使用history.push({pathname: '/personal', search: 'test=22222'}),其中search鍵對(duì)應(yīng)的值就是拼接在地址欄的數(shù)據(jù)

    import React from 'react'import { useHistory } from 'react-router-dom'export default ()=> {
    	const history = useHistory()
    	// 頁面跳轉(zhuǎn)方法
    	history.push({pathname: '/personal', search: 'test=22222'})
    	return 123}
  • 接收的方法。數(shù)據(jù)都是存儲(chǔ)在useLocation中的search獲取

    import React from 'react'import { useLocation } from 'react-router-dom'export default ()=> {
    	const location = useLocation()
    	// 頁面跳轉(zhuǎn)方法
    	console.log(location, 'props')
    	return 123}

    react路由跳轉(zhuǎn)的方式有哪些

2. 使用state的形式,頁面刷新不會(huì)丟失數(shù)據(jù),并且地址欄也看不到數(shù)據(jù)

  • 跳轉(zhuǎn)的方法是使用history.push({pathname: '/personal', state: {test: 'dashboard'}}),其中search鍵對(duì)應(yīng)的值就是拼接在地址欄的數(shù)據(jù)

    import React from 'react'import { useHistory } from 'react-router-dom'export default ()=> {
    	const history = useHistory()
    	// 頁面跳轉(zhuǎn)方法
    	history.push({pathname: '/personal', state: { test: 'dashboard' }})
    	return 123}
  • 接收的方法。數(shù)據(jù)都是存儲(chǔ)在useLocation中的search獲取

    import React from 'react'import { useLocation } from 'react-router-dom'export default ()=> {
    	const location = useLocation()
    	// 頁面跳轉(zhuǎn)方法
    	console.log(location, 'props')
    	return 123}

    react路由跳轉(zhuǎn)的方式有哪些

關(guān)于“react路由跳轉(zhuǎn)的方式有哪些”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí),可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會(huì)為大家更新不同的知識(shí)點(diǎn)。

網(wǎng)站題目:react路由跳轉(zhuǎn)的方式有哪些
分享網(wǎng)址:http://www.chinadenli.net/article34/ieoese.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)網(wǎng)站設(shè)計(jì)公司電子商務(wù)定制開發(fā)品牌網(wǎng)站設(shè)計(jì)定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)