redirect in react
window.location.href = "http://mywebsite.com/home.html";<Route exact path="/">
{loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>import { Route, Redirect } from 'react-router'
<Route exact path="/" render={() => (
loggedIn ? (
<Redirect to="/dashboard"/>
) : (
<PublicHomePage/>
)
)}/><Route exact path="/">
{loggedIn ? <Redirect to="/dashboard" /> : <PublicHomePage />}
</Route>state = { redirect: null };
render() {
if (this.state.redirect) {
return <Redirect to={this.state.redirect} />
}
return(
// Your Code goes here
)
}
// update the redirect
this.setState({ redirect: "/someRoute" });import React from 'react'
import { Redirect } from 'react-router-dom'
const ProtectedComponent = () => {
if (authFails)
return <Redirect to='/login' />
}
return <div> My Protected Component </div>
}
Also in JavaScript:
- get date now javascript
- angular material change placeholder color
- servicenow json insert
- Bitwise Operators js
- how to pass custom regex in jquery validation
- delete backspace on string js
- js scroll library
- if else javascript
- vuejs change prop value
- angular subscribe
- how to use http in development mode for nodejs
- how to find for lable in jquery
- react state scope
- js arrotondare superiore numero
- tsconfig.json not generated
- javascript combine objects
- js get initials from name
- add property to object javascript
- remove last 3 characters from string javascript
- javascript get attribute
- angular pipe to capitalize first letter
- javascript validation for login form
- acces store from vue console javascript
- ajax call too functions.php