当我尝试使用反应路由渲染下一页时,它会在上一页上渲染,我想要一个单独的页面在渲染后作为 HTML 中的标签,请帮助,下面是我的代码片段。
import React, { Component } from 'react';
import './App.css';
import NextPage from './Components/NextPage';
import NextPages from './Components/NextPages';
import { BrowserRouter as Router, Switch, Route, Link} from 'react-router-dom';
class App extends Component{
state = {
name:""
}
inputOnClick = (event) =>{
this.setState({name:event.target.value});
}
render(){
return(
<div className = "App">
<Router>
<Link to = "/NextPage">Click here</Link>
<br/>
<Link to = "/NextPages">Click here2</Link>
<Switch>
<Route exact path = "/NextPage" render = {(props)=><NextPage Name={this.state.name}/>} />
<Route exact path = "/NextPages" render = {(props)=><NextPages Name={this.state.name}/>} />
</Switch>
</Router>
<br/>
<input value = {this.state.name} onChange ={this.inputOnClick}></input>
</div>
);
}
}
export default App;