score:2
you have to use history in reactjs to get previous path and need to save in sessionstorage.
may be this will help you :
const saved_uri = 'app_plu';
const forbidden_uris = ['/login-response', '/'];
const default_uri = '/';
function setpostloginuri() {
// using just the pathname for demo, should be more detailed in production to
// include query params, hash bangs, etc
const currentpath = window.location.pathname;
const saveduri = sessionstorage.getitem(saved_uri);
if (forbidden_uris.includes(currentpath) || saveduri) {
return;
}
sessionstorage.setitem(saved_uri, currentpath);
}
function getpostloginuri(retain) {
const saveduri = sessionstorage.getitem(saved_uri);
if (!retain) {
sessionstorage.removeitem(saved_uri);
}
return saveduri || default_uri;
}
export default {
get: getpostloginuri,
set: setpostloginuri
};
and set in the app.js
and then in your login response page add this code ,
function loginresponse({ history, setuser }) {
const [error, seterror] = usestate(null);
useeffect(() => {
// the login redirect has been completed and we call the
// signinredirectcallback to fetch the user data
usermanager.signinredirectcallback().then(user => {
// received the user data so we set it in the app state and push the
// router to the secure or bookmarked route
setuser(user);
history.push(postloginuri.get());
}, ({ message }) => {
// usermanager throws if someone tries to access the route directly or if
// they refresh on a failed request so we just send them to the app root
if (message && redirecterrors.includes(message)) {
history.push('/');
return;
}
// for all other errors just display the message in production it would be
// a good idea to initiate a sign out after a countdown
seterror(message);
});
}, []);
return error;
}
export default loginresponse;
Source: stackoverflow.com
Related Query
- Redirect to same URL at client side after authentication from token server (identity server 4)
- How to Get Param Id from URL in express/mongo/mongoose on server side, axios/react/redux on client side
- Is there a cleaner way of getting current URL in both client and server side in isomorphic react apps?
- How to server side redirect to other page without reloading the page and still keeping the url in Nextjs app?
- how to get the ip address of the client from server side in next.js app?
- How to load JWT token on to React during initial download after authentication from Multi Page Application?
- How to download pdf from puppeteer using Nest js as Server Side and React in Client Side?
- how to validate session on react client after successful authentication from express session
- How to handle authentication from a Node Express redirect to React Client (react-router-dom and useContext)
- React Router with Meteor: How to remove code param from URL after redirect from OAuth without reload
- React JS : Migrate from server rendering to pure client side
- ReactJS: Apollo Client set Authentication Token after User is Authenticated
- How could i use the routing in reactjs to redirect from one page after loading to another url
- Redirect url to www in reactjs nextjs as a server side 301
- React server side rendering is not updating after client side route change
- Trying to migrate from React router v3 to v5 , Unable to figure out how to pass 'props.children' and redirect after authentication
- Calling server side method from client returns undefined
- Consistent url routing on client side React app served from Express
- How to remove duplicate slashes from URL in Next Js.How to intercept and modify a request on the server side getServerSideProps?
- Pass value from server side to client side in Next JS using getInitialProps
- Setting up JWT - Passing token from server to client in header, but cannot parse header in client
- Different markup generated on server and client from the same JSX code
- Client side state is not hydrated from server on page reload
- showing an alert box from server side to client side in express js, react js
- Sending form data from react client side to node.js server side
- React_Display Image from server side into Client
- How to invoke a React-router client side redirect to a new url in JS without using <Link>
- NextJS redirect user back to the router came from after authentication
- Display image at client side (react) from mongoDB (that has a path to a folder that stores the images at server side)
- Using react, axios and django, i'm trying to send data from my client side to my server but I can't get the data
More Query from same tag
- You may need an appropriate loader to handle this file type upload image file
- Filling d3.js map with colors depending on data from json
- how to use Height auto in react native?
- React fetch, “credentials: include”, breaks my entire request and I get an error
- What's the difference between npm run dev and npm run start in Next.js?
- React stateless component with controlled form Elements?
- What is React component 'displayName' is used for?
- JavaScript return tab order to top of the page after blur event
- Icon png file failed to load when create-react-app deploy on server
- how to properly make div tab in javascript to work with reactjs
- How can I test an internal method inside a component in React?
- React, implementing Dark-Light-Mode with localStrorage
- Import props in Storybook select options
- How can I use lodash to filter value between two date?
- Open Sign Modal when an unauthorized user accessing private route in reactjs
- How to add delete button function in the Table ReacJst?
- hide imported child component on hover using styled-components
- Cannot align Nav Items to right in Bootstrap React
- Using Mocha to test props on a rendered SVG component in React
- Checking if local storage has object inside in ReactJS
- How to refresh data of one component from another component in react js
- How to write arrow function in a normal function
- The input textbox is not letting me insert a value
- Select control created in React does not reset on browser refresh (IE11 and Edge)
- Why is React asking for repeated props in static propTypes?
- Warning: Did not expect server HTML to contain a <li> in <ul>. in React/Redux Server side Rendering
- Geolocation - can't get latitude and longitude in React/Redux app
- Blank Page when creating a route manager
- Dialog with Transition throwing JS warning "findDOMNode is deprecated in StrictMode"
- How to compare two arrays in react