user15530512
user15530512

Reputation:

React Router not showing a page - React JS

So I'm trying to make a web application with react router dom but the problem is React Router is not showing the page, When I click on the link it redirects but shows me nothing, When I go to http://localhost:3000/login/ manually it still does not show me anything, but it shows me the home page. Here is my code:

import { BrowserRouter as Router, Route, Link } from 'react-router-dom'

function HomeScreen() {
 return (
   <Link to='login/'>Login Screen</Link>
   // I'm only showing the related parts to keep this question small
)
}


function LoginScreen() {
    return (
        <h1>Login Screen</h1>
    )
}



function App() {
    return (
    <Router>
        <Route path='/' exact component={HomeScreen} />
        <Route path='login/' component={LoginScreen} />
    </Router>
    )
}



export default App

Upvotes: 0

Views: 66

Answers (1)

Ali Taghipour
Ali Taghipour

Reputation: 114

you have a mistake in navigation login route

  // here the problem --> login/  <Route path='login/' component={LoginScreen} />


function App() {
    return (
    <Router>
        <Route path='/' exact component={HomeScreen} />
        <Route path='/login' component={LoginScreen} />
    </Router>
    )
}

Upvotes: 1

Related Questions