Redirect in React Router tut 20
Redirect in React Router
Redirect can use to redirect page to given path
when page doesn't exsist , it can be used instead of
showing 404 error page, so when user enter in wrong url
it will redirect to certain given path
import React from 'react'
import {Route , Switch, Redirect} from "react-router-dom"
import Contact from './RContact'
import About from './RAbout'
import ErrorMsg from './ErrorMsg'
import Navbar from './Navbar'
import User from './UseParams'
import Search from './RSearch';
let Service = ()=>{
return(<>
<h1>This is Service page</h1>
</>)
}
let Router = ()=>{
return(<>
<Navbar/>
<Switch>
<Route exact path="/" component={()=><About text="About US" />}/>
<Route exact path="/contact" render={Contact}/>
<Route path="/contact/service" component={Service}/>
<Route path="/user/:fname/:lname" component={User}/>
<Route path="/search" component={Search}/>
{/* <Route component={ErrorMsg}/> */}
<Redirect to="/"/>
{/* Redirect can use to redirect page to given path
when page doesn't exsist , it can be used instead of
showing 404 error page, so when user enter in wrong url
it will redirect to certain given path */}
</Switch>
</>)
}
export default Router;
Comments
Post a Comment