Reactjs 动态组件不';我不在办公室工作
我想在React中添加一个动态组件,但它不起作用。我得到了正确的组件名称,但看起来我的变量在其中不起作用:Reactjs 动态组件不';我不在办公室工作,reactjs,react-router,Reactjs,React Router,我想在React中添加一个动态组件,但它不起作用。我得到了正确的组件名称,但看起来我的变量在其中不起作用: componentDidMount() { const currentLocation = this.props.location.pathname; let route_name = 'Dashboard'; for (let i = 0; i < Route.length; i++) { if (Route[i].path == current
componentDidMount() {
const currentLocation = this.props.location.pathname;
let route_name = 'Dashboard';
for (let i = 0; i < Route.length; i++) {
if (Route[i].path == currentLocation) {
route_name = Route[i].name;
break;
}
}
this.setState({
route_name: route_name
});
}
render() {
return (
<div className="admin-content">
<this.state.route_name />
</div>
);
}
componentDidMount(){
const currentLocation=this.props.location.pathname;
让route_name=‘Dashboard’;
for(设i=0;i
为了直接按名称渲染组件,需要先将其指定给变量,然后再渲染它
componentDidMount() {
const currentLocation = this.props.location.pathname;
let route_name = 'Dashboard';
for (let i = 0; i < Route.length; i++) {
if (Route[i].path == currentLocation) {
route_name = Route[i].name;
break;
}
}
this.setState({
route_name: route_name
});
}
render() {
const RouteName = this.state.route_name;
return (
<div className="admin-content">
<RouteName/>
</div>
);
}
componentDidMount(){
const currentLocation=this.props.location.pathname;
让route_name=‘Dashboard’;
for(设i=0;i
为了直接按名称渲染组件,需要先将其指定给变量,然后再渲染它
componentDidMount() {
const currentLocation = this.props.location.pathname;
let route_name = 'Dashboard';
for (let i = 0; i < Route.length; i++) {
if (Route[i].path == currentLocation) {
route_name = Route[i].name;
break;
}
}
this.setState({
route_name: route_name
});
}
render() {
const RouteName = this.state.route_name;
return (
<div className="admin-content">
<RouteName/>
</div>
);
}
componentDidMount(){
const currentLocation=this.props.location.pathname;
让route_name=‘Dashboard’;
for(设i=0;i
不幸的是,它抛出了这个错误使用了不正确的大小写。对React组件使用PascalCase,对HTML元素使用小写。
HeroBanner是我的组件的名称,它已经是pascal大小写@shubhamun了。幸运的是,它抛出了这个错误使用了不正确的大小写。对React组件使用PascalCase,对HTML元素使用小写。
HeroBanner是我的组件的名称,它已经是pascal大小写@shubham了