在 react 组件的 componentDidMount 方法中打印一下 this.props,在浏览器控制台中查看输出以下:html
其中页面的 url 信息全都包含在 match 字段中,以地址:react
localhost:3000/app/knowledgeManagement/modify/STY20171011124209535/3/1507701970070/0/?s=1&f=7浏览器
为例,其中各个参数定义对应以下:session
localhost:3000/app/knowledgeManagement/modify/:studyNo/:stepId/:randomNum/:isDefault/?s=&fapp
首先打印 this.props.match :dom
能够看到 this.props.match 中包含的 url 信息仍是很是丰富的,其中this
经过以上分析,获取 url 中的指定参数就十分简单了,下面是几个例子:url
// localhost:3000/app/knowledgeManagement/modify/STY20171011124209535/3/1507701970070/0/?s=1&f=7 // localhost:3000/app/knowledgeManagement/modify/:studyNo/:stepId/:randomNum/:isDefault/?s=1&f=7 // 获取 studyNo this.props.match.match.params.studyNo // STY20171011124209535 // 获取 stepId this.props.match.match.params.stepId // 3 // 获取 success const query = this.props.match.location.search // '?s=1&f=7' const arr = query.split('&') // ['?s=', 'f=7'] const successCount = arr[0].substr(3) // '1' const failedCount = arr[1].substr(2) // '7'
连接描述spa