发布时间:2022-12-27 19:30
<Link to={`/home/message/detail/${msgObj.id}/${msgObj.title}`}>{msgObj.title}Link>
<Route path="/home/message/detail/:id/:title" component={Detail}/>
const {id,title} = this.props.match.params
<Link to='/demo/test?name=tom&age=18'}>详情Link>
<Route path="/demo/test" component={Test}/>
this.props.location.search
import qs from 'querystring'
const {search} = this.props.location
const {id,title} = qs.parse(search.slice(1))
详情Link>
<Route path="/demo/test" component={Test}/>
this.props.location.state
父组件内容
import React, { Component } from 'react'
import {Link,Route} from 'react-router-dom'
import Detail from './Detail'
export default class Message extends Component {
state = {
messageArr:[
{id:'01',title:'消息1'},
{id:'02',title:'消息2'},
{id:'03',title:'消息3'},
]
}
render() {
const {messageArr} = this.state
return (
{
messageArr.map((msgObj)=>{
return (
-
{/* 向路由组件传递params参数 */}
{/* {msgObj.title} */}
{/* 向路由组件传递search参数 */}
{/* {msgObj.title} */}
{/* 向路由组件传递state参数 */}
{msgObj.title}
)
})
}