cannot GET // React

Asked

Viewed 170 times

-2

We created our first project in React, local everything works normal..

When we host on the web ... the system enters the address for example https://www.dominio.com/painel_teste

At that moment appears the login screen (is placed user and password ) and enters the system screen (ok) address https://www.dominio.com/painel_teste/termometro ....

When trying to update the page ... F5 ... the address keeps the same but the message appears on the screen

cannot GET //thermometer ...

as if it were some route problem ....

We have tried several alternatives and all without success....

Some considerations 1 ) I managed the project build
2 ) Move the build folder up to the test panel folder (on the server) 3 ) I created a configuration file "painel_teste.js" with the following configuration

var http = require('http');
const express = require('express');
const app = express();

const baseDir = `${__dirname}/build/`
app.use(express.static(`${baseDir}`))
app.get('/painel_teste', (req, res) => res.sendfile('index.html' , { root : baseDir } ))

const port = 21164;
app.listen(port)

4 ) Archive of Routes

const Routes = () => (

<Router>
    <Switch>
        <Route exact path="/painel_teste" component={Login} />
        <PrivateRoute exact path="/painel_teste/termometro" component={TermometroRRC} />
       <Route exact path="/logout" component={Logout} />
    </Switch>
</Router>

);

I await suggestions ....

1 answer

0

Maybe it is a bad configuration on the server, for example when using Nginx, you need to add to the configuration file:

location / { root /folder/subfolder/build; try_files $uri /index.html; }

Where that try_files refers, that if the route is not configured on the server, it will redirect the main page, where it will perform all the routes part of the application.

Another example is an application hosted in Netfly, where you need to create a file _redirects with the content /* /index.html 200, inside the briefcase public, before building the React application.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.