0

There is a need to push to a specific location say '/login' based on statuses inside interceptor.

Is there a way to directly push to a location?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Mukundhan
  • 3,284
  • 23
  • 36

1 Answers1

1

A quick and ugly way could be. window.location.replace('/myUrl')

UPDATE

A WorkAround could be

/**RootComponent*/

export const myRouter = {};
@withRouter()
Class RootComponent extends React.Component {
    constructor(props) {
       super(props);
       myRouter = this.props.router;
    }
    render() {
      return <Provider store={store}>
            <MainComponent/>
         </Provider>
    }
}

/**Interceptor*/

import { myRouter } from 'RootComponent';

if (status == 401) {
    myRouter.push('/myUrl');
}
Mukundhan
  • 3,284
  • 23
  • 36