Stack Overflow Asked by Keurig on January 31, 2021
EDIT(8/20/2020):
Still trying to figure out how to fix this issue.
I’m trying to output a 404 in nginx when there is no route for it in the react app. For my react app I’m using the browser router for index.js and for the routes I’m using react router dom. it looks like this
function App() {
return (
<div className="App">
<h1>Main Page</h1>
<Switch>
<Route path="/dash" exact={true} component={SecondPage} />
</Switch>
</div>
);
}
My nginx config looks like this
server {
listen 80 default_server;
listen [::]:80 default_server;
index index.html;
server_name _;
root /var/www/myapp;
location / {
root /var/www/myapp/build;
try_files $uri /index.html =404;
}
}
And when I go to the address 192.168.1.199 all the features work except when you go to a random page example 192.168.1.199/randompage it outputs the main react app which does not make much sense.
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP