Remember web address to navigate to it later

Hi,

I want to make a registration form. After the registration is complete, I want to navigate to the page the user was on before he/she open the registration form, so the previous URL needs to be remembered.
I don’t want to use a lightbox. Is there any way to do this? Can you give me an example?

Many thanks!

You need to get the referrer: https://www.wix.com/corvid/reference/wix-window.html#referrer

If there is no page change after submitting, then you can use https://www.wix.com/corvid/reference/wix-location.html#to to go back (you will just have to remeber it in a var)

If there is a page change, then, instead of remeberibg it in code, you will have to remeber it outside the code, e.g. using locale storage: https://www.wix.com/corvid/reference/wix-storage.html

referrer won’t work here, because Wix site is an SPA (The referrer will only be useful, if you want to redirect to the last external page outside the your site).

Hey J.D., didn´t know that, thanks. So to answer Quinten´s question, what should he then do? Use a URL param from the triggering page, remember or store it, then read and go back?

Yes. He can either use URL params or storage(*).
I think URL params are a little bit faster, but I’m not sure and it’s insignificant anyway.

(*) There’re other (uglier) ways to do it, but these are the simplest

IF you wanted to implement this in a clean way (without having to add seperate code to every page) you would add some code “store_this_page_name” at site level, after reading the (possible existing) former value, which would be the referrer.
This would work if there is no page change between form and submit. But if there is, then “referrer page” would hold the FORM, not the page before the form. Any ideas?

The question is what exactly you want to achieve:
If you want save the page you started from without having to copy the code, you can have the code in the site code panel and do something like:

import wixLocation from 'wix-location';
import {session} from 'wix-storage';
let formPaths = ["formP1", "formP2", "formP3"];
let currentPath = wixLocation.path[0];
if (!formPaths.includes(currentPath)){
  session.setItem("lastPage", currentPath);
}

I actually managed to figure it out myself.

On the SITE tab (my button to save the address in shown on all pages), I put:

export function theSaveButton_click(event) {
    session.setItem("prevAddress", wixLocation.url);
}

On the relevant page tab (from which I want to navigate to the saved page), I put (underneath my event handler):

export function theBackButton_click(event) {
    wixLocation.to(session.getItem("prevAddress"))
}

Very good, that´s exactly how it should be done. I was wondering how far you got.