0

I have an LWC page in this Playground

here if I click next button it navigates to next page and previous will navigates back to previous page now if I click next from 1st page then it will navigate to 2nd page as expected but if I refresh page from 2nd page then instead of rendering 2nd page it renders 1st page, I know this behavior is expected but is there any way to resolve this thing?

1 Answer 1

1

You would need a system to manage state. I can think of two ways to do this: Cookies, records.

For instance, if you save the value of every field in cookies when they click next, if they refresh the page you can then check the cookie to see if the fields have already been filled out and validate them, then send them on to page 2 (probably save the page number in a cookie as well just to make sure they did infact hit next, don't forget to validate the stored values to make sure noone is trying to do something nefarious).

References:

  1. JavaScript Cookies
  2. Apex Cookies (note there are questions on this site with other users having issues with accessing cookies via apex in lwcs)

This same thing can be achieved via a record in SFDC. When the next button is clicked, save information to a record in the DB and when a refresh is performed make sure to pull this information out. This approach will take extra steps to make sure that you are working with the same user in the same session, I would also expect some amount of record bloat so you may want an automated process to clean up unfinished records after a certain period.

It may also help to create a "continue where you left off" pop up to give users the ability to start over if they wish.

2
  • Thank you for your response gNerb, I cannot use 2nd and 3rd approach because of the current structure, could you pleas provide some more information regarding the first approach please?
    – gs650x
    Commented Apr 21, 2020 at 3:33
  • @gs650x updated the answer with some references you can check out.
    – gNerb
    Commented Apr 21, 2020 at 22:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .