0

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
1

1 Answer 1

1

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>
    )
}

Sign up to request clarification or add additional context in comments.

1 Comment

Someone downvoted you but your answer works! Thanks so much!

Your Answer

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