ReactJS Basic Routing


Install router npm package.
npm install react-router-dom

import React, { Component } from 'react';
import './App.css';
import { BrowserRouter as Router, Switch, Route, Link } from "react-router-dom";

const Home = () => {
  return <h3>Home page</h3>
}

const About = () => {
  return <h3>About page</h3>
}

const QA = () => {
  return <h3>QA</h3>
}

class App extends Component {
  render() {
    return (
      <Router>
        <Switch>
          <Route path="/" exact component={Home}>Home</Route>
          <Route path="/about" exact component={About}>About</Route>
          <Route path="/qa" exact component={About}>QA</Route>
        </Switch>
      </Router>
    );
  }
}
export default App;

Share on Google Plus

About Ram Pukar

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment

0 comments:

Post a Comment