如果我点击主页上的链接,他们会工作,将我引导到其他页面。如果我在不是主页的页面中重新加载浏览器(Google Chrome,FireFox,Microsoft Edge),则只会出现此问题。
error 404: The requested URL /projects was not found on this server
我创建的网站在开发中运行良好且没有任何错误,我运行yarn build
并将构建文件夹上传到我的服务器。
*我也有此错误:Error during service worker registration: DOMException: Only secure origins are allowed
,我发现这意味着我的网站没有https 。它是否会导致上述问题?*< - 它没有。
我怀疑原因可能出在我的 App.js 文件中,所以这里是:
import React from 'react';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom';
import NavBar from './components/NavBar';
import Home from './pages/Home';
import Projects from './pages/Projects';
import About from './pages/About';
import NoMatch from './pages/NoMatch';
const App = () => (
<Router>
<div>
<NavBar/>
<Switch>
<Route exact path="/" component={Home}/>
<Route exact path="/projects" component={Projects}/>
<Route exact path="/about" component={About}/>
<Route component={NoMatch}/>
</Switch>
</Router>
);
export default App;