React Router 4.1.1 not showing when I click on the <Link> link

I am just trying to click on a component and react to the registry which it needs to render. But I just can't archive it. This is what I have so far:

Index.js (Here I tried to keep all my routes)

import React from "react";
import ReactDOM from "react-dom";
import Main from "./pages/index/main.js";
import Login from "./pages/signin/signin.js";
import { BrowserRouter as Router, Route, Switch} from "react-router-dom";
ReactDOM.render(
  <div>
    <Router>
      <Switch>
        <Route exact  path="/" render={()=> <Main />}/>
        <Route path="/login" render={()=> <Login />}/>
      </Switch>
    </Router>
  </div>,
  document.getElementById("root")
);

      

Header.JS (where I have my link tags setup)

import React from "react";
import style from "./../acc/css/navbar.css";
import { BrowserRouter as Router, Link} from "react-router-dom";
export default class Header extends React.Component {
    render() {
        return (
            <Router>
    <section className={style.nav} id="nav">
            <ul>
        <li><Link to="/">Home</Link></li>
        <li><Link to="/login">Login</Link></li>
            </ul>
        </section>
        </Router>
        );
    }
}

      

Currently when I manually go to / it displays the main connection and when I manually go to / login it displays the Login connection. However, when I click on the component, it doesn't only display the url / login or dash changes. I was wondering if there is any solution to this problem?

Edit 1

Main.js code

import React from "react";
//import compunts
import Header from "./../header.js";
import Qoute from "./qoute.js";
import Grades from "./grades.js";

export default class Main extends React.Component {
    render() {
        return (
      <div id="continor">
                <Header />
                <Qoute />
                <Grades />
            </div>
        );
    }
}

      

Signin.js

    import React from "react";
    import Header from "./../header.js";
    import Qoute from "./qoute.js";
    import Form from "./form.js";
    export default class Login extends React.Component {
        render() {
            return(
          <div>
          <Header />
            <section id="info">
              <div className="containor">
                <div className="row">
                  <Qoute />
                  <Form />
                </div>
              </div>
            </section>
          </div>
            );
        }
    }

      

To find out, I tried

<Route exact path="/" component={Main}/>

      

and it still doesn't work. Any solutions?

+3


source to share





All Articles