next-pwa icon indicating copy to clipboard operation
next-pwa copied to clipboard

Regarding PWA redirect when reopen application

Open eureka928 opened this issue 4 years ago • 2 comments

Hello I am getting one issue for my PWA

I install PWA and open as url like {domainname}/test-result, and close it. But after that, when I tried to reopen application, it redirects to homepage instead of test-result page.

Is there any solution for this? Thank you

eureka928 avatar Aug 20 '21 08:08 eureka928

That's by design of PWA. It gives user experience that people usually expect like an native app. If you want to show user the page where they left last time, you have to implement yourself using local storage or index db or other methods to redirect user.

shadowwalker avatar Aug 21 '21 17:08 shadowwalker

What you could do is store in a cookie  (make sure the cookie is not a Session cookie) the current path each time a user navigate in your app. Then, add a getServerSideProps function in the test-result page and you can redirect the user to the path store in the context.req.cookies.path like so :

export const getServerSideProps: GetServerSideProps = async (context) => {
  // Get the cookies of the incoming req
  const cookies = context.req.cookies;

  return {
    redirect: {
      destination: cookies.path ,
        permanent: false,
    },
  };
};

You can read this topic to learn more about redirection

RomainGuarinoni avatar Nov 26 '21 09:11 RomainGuarinoni