reactjs - 反应路由器不改变路径
问题描述
import * as React from "react";
import { BrowserRouter as Router,Switch,Route,Link,useHistory } from "react-router-dom";
import Login from "./login/index";
import MainFrame from "./main-frame/index";
const MainWrapper = () => {
return (
<div>
<Router>
<Switch>
<Route path="/main-frame">
<MainFrame />
</Route>
<Route exact path="/">
<Login />
</Route>
<Route exact path="/i">
<p>sdf</p>
</Route>
</Switch>
</Router>
</div>
);
};
export default MainWrapper;
这是我的简单代码。当我去浏览器并手动输入http://localhost:8080/i时,路径没有改变。只有 http://localhost:8080/有效。http://localhost:8080/main-frame都 不起作用。以上都给出了错误:
Cannot GET /i
Cannot GET /main-frame
解决方案
我认为你必须修复它
<Router>
<Switch>
<Route path="/main-frame" component={MainFrame} />
<Route exact path="/" component={Login} />
{/* <Route exact path="/i"> */}
</Switch>
</Router>
参考这个https://codeburst.io/getting-started-with-react-router-5c978f70df91
推荐阅读
- loops - while循环中的动态“修改”子句
- laravel - Laravel 7.4:无法在服务器上上传徽标
- javascript - 根据类名Javascript更改伪元素的颜色
- angular - Angular Material Mat-Menu 在打开之前不会检查可用空间,并会切断
- python-3.x - Python3:比较两个 CSV 文件以识别新文件中的新内容,忽略旧文件中的内容
- cython - Cythonize 以“致命错误 C1002:编译器在传递 2 中的堆空间不足”结束
- c++ - 在c ++中输入字符串作为字符数组
- pandas - 删除带有条件的重复项并在需要时合并
- spring-integration - How - Spring 集成:即使应用程序崩溃也能可靠交付
- ios - 从 scenedelgate.swift 初始化 tabbarcontroller