Create routes using the Route of React

1

Next I'm using the react-router-dom while I'm serving the project folder as if it were root works, the routes go to the specific components my problem is when I put in a server:

The part of the front where the react is I put inside the folder / app and my php scripts that interact with the front in / server.

Different when I put the react in the root / it works perfectly.

<Router>
    <div>
      <a href="./">inicio</a><span> </span>
      <a href="./maps">maps</a><span> </span>
      <a href="./cadastro">cadastro</a>


      <Route path={"/app/maps"} component={TelaMaps} />
      <Route path={"/app/cadastro"} component={TelaCadastro} />

    </div>
  </Router>
    
asked by anonymous 15.10.2017 / 16:30

1 answer

0

Your problem is the route you make on your server for the React files.

If you are using webpack and express you just have to make a combination of the two to serve your files in the desired place.

An example:

Webpack output:

output: {
    filename: '[name].js',
    path: path.resolve(__dirname, 'dist'),
    publicPath: '/'
  },

Express configuration:

const app = express();
app.use(express.static('dist'));
    
19.10.2017 / 18:19