Skip to content

Instantly share code, notes, and snippets.

@freakflames29
Created March 30, 2021 15:56
Show Gist options
  • Save freakflames29/c3a9a6c302b0ebc5820c115014fdb662 to your computer and use it in GitHub Desktop.
Save freakflames29/c3a9a6c302b0ebc5820c115014fdb662 to your computer and use it in GitHub Desktop.
Routes in react
//npm install react-router-dom
// run this after creating a react project
/***************************************** App.js *******************************************/
import "./App.css";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import Compo from './Thec'
import About from './About'
function App() {
return (
<div className="App">
<Router>
<Switch>
<Route path="/sourav">
<About/>
</Route>
<Route path='/'>
<Compo/>
</Route>
</Switch>
</Router>
</div>
);
}
export default App;
/**************************** About.js (<About/> component) **************************/
import React,{Component} from 'react'
import { Link } from "react-router-dom";
class About extends Component
{
render()
{
return(
<div>
<h1>My name is sourav das i am a full stack coder</h1>
<Link to ='/'>Go to home</Link>
</div>
)
}
}
export default About;
/************************ The home component ********************************/
// import React from 'react'
import { Link } from "react-router-dom";
const Compo=()=>
{
return(
<div>
<h1>This is a cool thing</h1>
<Link to='/sourav'>
This is link to tag
</Link> |
<a href="/sourav">This is a tag</a>
</div>
)
}
export default Compo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment