0

I have basic react app.

    import React, { Component } from 'react'
    import ReactDOM from 'react-dom'
    import {BrowserRouter as Router, Link, Route} from 'react-router-dom'
    import registerServiceWorker from './registerServiceWorker';
    import './App.css'
    import About from './routerTest/About';
    import Users from './routerTest/Users';
    import User from './routerTest/User';

     class App extends Component {

      render() {
        return (
    <div className="App">
  <header>
    <Link to="/">Home</Link>
    <Link to="/about">About</Link>
    <Link to="/users">Users</Link>
    </header>
    <Route  path="/about"   component={About}/>
    <Route  path="/users"   component={Users}/>
    <Route  path="/" exact HomePage  render={() => <h1>HomePage</h1>}/>

    </div>
          )
      }
    }


    ReactDOM.render(
      <Router>
       <App />


      </Router>
      , document.getElementById('root'));
      registerServiceWorker();

About.js

import React from 'react'

const About = () => {
    return (`enter code here`
        <div>
            <h1>About</h1>
        </div>
    )
}

export default About

when I work on localhost everything works fine. But when I deploy it to any hosting service.(ex:alwaysdata, webhost) and refresh the page in any route it gives me error You don't have permission to access /about on this server. What is wrong here

1 Answer 1

2

For React Router V4 Users:

<Router history={hashHistory} >
does not work in V4, please use HashRouter instead:

import { HashRouter } from 'react-router-dom'

<HashRouter>
  <App/>
</HashRouter>
Sign up to request clarification or add additional context in comments.

2 Comments

can you say why should I use hashrouter instead of normal browserRouter?
I had the same problem, and I solved it using it. If you want a more detailed explanation, I suggest you read this. I referenced this place. medium.com/@swatantramishra1/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.