我需要转到“其他”网页,但是当我单击“我的链接”时,它包装了按钮,URL发生了变化,但网页不变了
在App.js
中:
import {Route, Switch} from 'react-router-dom';
class App extends Component {
render() {
return (
<>
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/rooms" component={Rooms}/>
<Route exact path="/rooms/:room" component={Chat}/>
<Route exact component={Error}/>
</Switch>
</>
);
}
}
该组件:
import React, {Component} from "react"
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
...
<Link to="/rooms" style = {{textDecoration: "none"}}> //That link
<div class="btn" > {this.props.Title == "Sing Up" ?"Register Now!" :"Lets Go!"} </div>
</Link>
我希望在这里更改page.enter代码
答案 0 :(得分:0)
尝试在BrowserRouter
组件内部呈现应用程序。
import { Component } from "react"
import { BrowserRouter, Switch, Route, Link } from "react-router-dom"
class App extends Component {
render() {
return (
<BrowserRouter>
<Switch> etc </Switch>
</BrowserRouter>
)
}
}
该按钮还使用class
而不是className
。
<div className="btn">