Push and replace routes anywhere
npm install react-router-redirect```
yarn add react-router-redirect or npm install react-router-redirect --save
1. Include the component anywhere in your app below the component from react-router.
`
import {Redirector} from 'react-router-redirect';
const App = () =>(
)
`
2. Now you can change the Route from anywhere
import {push} from 'react-router-redirect';class TestComponent extends React.Component {
onClick = () => {
push("/login")
}
render() {
return
}
}
`$3
`
import { push } from 'react-router-redirect'; // or import replace, go, goForward, goBack
import client from 'client';
import clientLoginMutation from 'gql/mutations/clientLogin';const sagas = [
{
saga: 'MUTATION.LOGIN.SUCESS',
handler: ({ login }) => {
client
.mutate({ mutation: clientLoginMutation, variables: { user: login } })
.then(() => {
push('/dashboard');
});
}
}
];
export default sagas;
`$3
`
import {replace} from 'react-router-redirect';push("/")
class TestComponent extends React.Component {
``- push
- replace
- go
- goForward
- goBack