@Quintis

React router не работает в production build?

Доброго времени суток , react router не работает после билда , кто может помочь как исправить ? В режиме разработчика всьо нормально.
Код ошибки :
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)


Код роутов :
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;
  • Вопрос задан
  • 1093 просмотра
Пригласить эксперта
Ответы на вопрос 2
@abberati
frontend-разработчик
Раздавайте приложение с сервера, а не открывайте файлик из файловой системы.
Ответ написан
@DanyaSokolov
Вместо BrowserRouter используй HashRouter

Как не надо:
import { BrowserRouter as Router, Routes, Route, NavLink } from "react-router-dom";


Как НАДО:
import { HashRouter as Router, Routes, Route, NavLink } from "react-router-dom";
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы