I created react app react router 4.but I build my project using npm run build route URL not working and display 404 page.how can I fix that? I have no idea.this is my code
import React from "react";
import ReactDOM from "react-dom";
import registerServiceWorker from "./registerServiceWorker";
import { BrowserRouter as Router,Switch,Route } from "react-router-dom";
import { createMuiTheme, MuiThemeProvider } from "@material-ui/core/styles";
import "react-datepicker/dist/react-datepicker-cssmodules.css";
import "./styles/main.scss";
import App from "../App";
import AdminHome from "../pages/admin/home";
import Login from "../pages/login";
import PrivateRoute from "./privateRoute";
const theme = createMuiTheme({
palette: {
type: "dark"
}
});
ReactDOM.render((
Not Found
}/>
), document.getElementById("root"));
registerServiceWorker();
Can anyone help me to fix this?
Top comments (5)
This is an apache-related issue
Make sure your Apache server redirects every request to index.html file. write the following code to .htaccess
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
For me works! i don't have any htaccess rules before
i just sign there up to say thank you for your answer
you saved me from my horrible client
At this time, you are telling react to render "Not Found" with an additional "}/>" that doesn't seem to belong.
Follow along with the React Router Docs: reacttraining.com/react-router/web...
// First import the correct modules
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
/*
Your Code Here
*/
// Render your root Component to the DOM
ReactDOM.render((
// Wrapping Routes in Router
// Render Home Component
// Render Blog Component
// Only renders when no match was found
), document.getElementById("root"));
registerServiceWorker();
Use this as a template for the routing, but make sure to checkout the original documentation. They lay it out clean and simple.
Hope this helps :D
thanks for helping.routing component is not shown on the post