2

I deployed my react js site. but it can't load pages through url.

it can load homepage https://cekedu.netlify.app/ and when I click sign in it goes to the login page.

but I can't directly go to login page by entering url https://cekedu.netlify.app/login.

but it works in development.

import React from 'react' import './css/typicons.min.css' import ReactDOM from 'react-dom' import User from './components/user' import Header from './components/homeHeader' import Home from './components/home' import {Route, BrowserRouter as Router , Switch,Link} from 'react-router-dom'

import './index.css'
import './css/style.css'
import './css/bootstrap-grid.css'      

class App extends React.Component{    
    render(){
      return(
        <Router>          
          <Switch>
          <Route path="/login">
            <User/>
          </Route>
          <Route path="/">
              <Home/>
          </Route>
          </Switch>              
        </Router>
      )
    }
  }

ReactDOM.render(<App />,document.getElementById('root'));

3 Answers 3

2

You need to make sure that all paths respond with your the index.html page that your React app is used in.

For netlify, create a file named "_redirects" in the public foler and add this.

/* /index.html 200
Sign up to request clarification or add additional context in comments.

Comments

0

You can also try by using "exact" prop in Route of Home component.

<Route exact path="/"> <Home/> </Route>

1 Comment

I tryed this but still not working in deployed site.
0

Add "exact" prop to Route which it's path is also included by another Route's path. For example home path '/' is included in all paths so it needs to have exact keyword to differentiate it from other paths which start with '/*'.

<Router>          
   <Switch>
      <Route path="/login">
         <User/>
      </Route>
      <Route exact path="/">
         <Home/>
      </Route>
    </Switch>              
</Router>

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

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.