problem description
React modifies the project generated by Browserrouter to run yarn build for Hashrouter
but the generated project opens the page to access the subroute or 404 error
opens the index page to access the domain name is file:///D:/client/build/index.html-sharp/
after the access domain name is file:///D:/resume/19, the access error occurs. The error is as follows:
cannot find your file
the file may have been moved somewhere else or deleted.
ERR_FILE_NOT_FOUND
the environmental background of the problems and what methods you have tried
version of react-router-dom is 4.2.2
"react-router-dom": "^ 4.2.2",
related codes
/ / Please paste the code text below (do not replace the code with pictures)
The code in App.js is as follows:
import React, {Component} from "react";
import logo from". / logo.svg";
import {
Collapse,
Navbar,
NavbarToggler,
NavbarBrand,
Nav,
NavItem,
NavLink,
UncontrolledDropdown,
DropdownToggle,
DropdownMenu,
DropdownItem,
ListGroup,ListGroupItem
} from "reactstrap";
import Header from". / component/Header.js";
import Index from". / component/Index.js";
import Login from". / component/Login.js";
import MyResume from". / component/MyResume.js";
import Resume from". / component/Resume.js";
import Register from". / component/Register.js";
import AddResume from". / component/AddResume.js";
import EditResume from". / component/EditResume.js";
import Logout from". / component/Logout.js";
import {HashRouter as Router,
Route,
Switch,
Link
} from "react-router-dom";
class App extends Component {
render() {
return (
<Router>
<div className="App">
<Header/>
<div className="main">
<Switch>
<Route path="/register" component={Register} />
<Route path="/login" component={Login} />
<Route path="/logout" component={Logout} />
<Route path="/myresume" component={MyResume} />
<Route path="/resume/:id" component={Resume} />
<Route path="/addresume" component={AddResume} />
<Route path="/editresume/:id" component={EditResume} />
<Route path="/" component={Index} />
</Switch>
</div>
</div>
</Router>
);
}
}
export default App;
what result do you expect? What is the error message actually seen?
the project route generated by yarn build opens the child page access normally. Open the sub-page to access the domain name file:///D:/client/build/index.html-sharp/resume/19 instead of file:///D:/resume/19