我正在尝试使用 Route 参数,但我无法获取参数。
该页面根本没有显示任何内容,似乎未定义或空白。
如何从“wedding/:pageName”获取参数?
这里缺少什么?这是获取参数的最佳方法吗?
“pageName”不是ID,有问题吗?
提前致谢
我的 App.js
import React, { Component } from 'react';
import { BrowserRouter, Route } from 'react-router-dom';
import { connect } from 'react-redux';
import * as actions from '../actions';
import Header from './Header';
import Weddings from './Weddings';
class App extends Component {
render() {
return (
<div className="container">
<BrowserRouter>
<div className="container">
<Header />
<Route path="/wedding/:pageName" component={Wedding} />
</div>
</BrowserRouter>
</div>
);
}
}
export default connect(null, actions)(App);
婚礼.js
import React from 'react';
import WeddingPage from './weddings/WeddingPage';
const Wedding = () => {
return (
<div>
<WeddingPage />
</div>
);
}
export default Wedding;
婚礼页面.js
import React, { Component } from 'react';
class WeddingPage extends Component {
render() {
return (
<div>
{this.props.pageName}
</div>
);
}
}
export default WeddingPage;