O
O
oskar barin2018-10-28 23:56:09
React
oskar barin, 2018-10-28 23:56:09

Why are React links not working in production?

Wrote a note in React. Notebook consists of several pages. I used react-router v4 for navigation.
Everything works great locally. But after I did react build and put it on the server, problems started.
If I follow the "/new-task" link it works, but if I refresh the page it shows "The requested URL /new-task was not found on this server."
Here is a code example of how I wrote the routes

mport React from "react";
import { Route, Switch } from "react-router-dom";

import Main from './Main';
import Admin from './Admin';
import NewTask from './NewTask';
import TestData from './TestData';
import ReviewTask from './ReviewTask';

function Routes() {
    return (
      <div>
        <Switch>
          <Route exact path="/" component={Main} />
          <Route path="/new-task" component={NewTask} />
          <Route path="/login-admin" component={NewTask} />
          <Route path="/admin" component={Admin} />
          <Route path="/test-data" component={TestData} />
          <Route path="/review-task" component={ReviewTask} />
        </Switch>
      </div>
    );
}

export default Routes;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question