Q
Q
Quintis2020-12-31 19:54:48
React
Quintis, 2020-12-31 19:54:48

React router not working in production build?

Good day, react router does not work after the build, who can help how to fix it? Everything is fine in developer mode.
Error code :

react-dom.production.min.js:17 Uncaught DOMException: Failed to execute 'pushState' on 'History': A history state object with URL 'file:///C:/' cannot be created in a document with origin 'null' and URL 'file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/index.html'.
    at file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:10241
    at Object.confirmTransitionTo (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:7849)
    at push (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:10152)
    at navigate (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:16768)
    at onClick (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:16325)
    at Object.m (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:154582)
    at E (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:154725)
    at file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:154871
    at T (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:154957)
    at _ (file:///C:/Users/%D0%9C%D1%96%D1%88%D0%B0/Desktop/REACT/max-shop/max-shop/build/static/js/2.4869c205.chunk.js:2:155406)

Route code :
import React from 'react';
import './App.css';
import Navbar from './components/Navbar';
import Magazine from './pages/Magazine';
import Basket from './pages/Basket';
import ProductItem from './pages/ProductItem';
import {  Switch,  Route } from "react-router-dom";
import Error from './components/Error';
import { Provider } from 'react-redux';
import store from './reducers/reducer'



function App() {
  return (
    <Provider store={store}>
    <div className="App">
    <Navbar/>
    <Switch>
    <Route exact path="/" component={Magazine}  />
    <Route exact path="/basket" component={Basket}  />
    <Route exact path="/item/:slug" component={ProductItem}  />
    <Route  component={Error}  />
    </Switch>
    </div>
    </Provider>
  );
}

export default App;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2020-12-31
@abberati

Distribute the application from the server, and do not open the file from the file system.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question