在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網絡安全  HTML/ react-router4 如何傳遞參數并接收

react-router4 如何傳遞參數并接收

問題描述

剛開始學習react,在react-router4傳遞參數這里卡住了,請各位大神幫幫忙。

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

相關代碼

// 請把代碼文本粘貼到下方(請勿用圖片代替代碼)

import React from 'react';
export default class ComponentList extends React.Component{

constructor (props){
    super(props)
    console.log(this.props.match.params.id);
}
render(){
    return(
        <div>
            <h2>這里是列表頁面</h2>
            <h2>id是: {this.props.match.params.id}</h2>
        </div>
    )
}

}

你期待的結果是什么?實際看到的錯誤信息又是什么?

就是想獲取到url上的參數id,/index.html#/user/123123 就是這個123123.
console.log(this.props.match.params.id);這句話能把123123打出來。
但是 <h2>id是: {this.props.match.params.id}</h2>這里就報錯。
我應該怎么寫才能在return里面獲取到這個id參數呢?拜托各位求教

回答
編輯回答
伐木累
<Route path='/user/:id' component={ComponentList} />
2017年3月11日 08:57
編輯回答
忘了我
<Switch>
            <Route exact path='/' component={ Home } />
            <Route path='/about/:number' component={ About } />
</Switch>

結合

<Link key={item} to={`/about/${item}`}>about{item}</Link>
2017年1月7日 16:11