我正在尝试创建一个仪表板结构,通过单击按钮重定向到其他组件。
我能够进行URL更改,但是如果不对该URL进行硬重装,仍然无法加载该页面。
我的代码如下: Navigate.JS
import React from 'react';
import {
BrowserRouter as Router,
Switch,
Route,
} from "react-router-dom";
import SalesDashBoard from "./salesDashBoard";
import OrderScreen from "./OrderScreen";
function SDNavigator(){
return(
<div>
<Router>
<Switch>
<Route exact path="/salesDesk" component={SalesDashBoard}/>
<Route exact path="/salesDesk/OrderScreen" component={OrderScreen}/>
</Switch>
</Router>
</div>
)}
export default SDNavigator;
SalesDashBoard.js
import React from 'react';
import {BrowserRouter as Router, Link} from "react-router-dom";
import Button from "@material-ui/core/Button";
function SalesDashBoard() {
return (
<Router>
<div>
<h3>Dashboard Links</h3>
<Button
component={Link} to="/salesDesk/OrderScreen"
variant="contained"
color="primary"
type="submit"
>
Login
</Button>
</div>
</Router>
)
}
export default SalesDashBoard;
OrderScreen.js
import React from 'react';
function OrderScreen() {
return (
<div Order Screen />
);
}
export default OrderScreen;
单击并更改URL后重新加载时,页面正在加载,但没有重新加载,仍显示在“仪表板”页面。
PS:我已经从App.js-> DashBoard.js路由了,那很好。
答案 0 :(得分:3)
尝试一下
function SalesDashBoard() {
return (
// Remove Router
<div>
<h3>Dashboard Links</h3>
<Button
component={Link} to="/salesDesk/OrderScreen"
variant="contained"
color="primary"
type="submit"
>
Login
</Button>
</div>
)
}