Parse URL to get a parameter

Hi every body
When somebody click on a link like www.mysite.com/test?id=1234 I need that the page “test” include a script to parse the URL and get the value “1234” because I need to use it to update a variable.

I’ve tried using something like the following code but it doesn’t work:


import wixLocation from ‘wix-location’;
$w.onReady(function () {
let query = wixLocation.query;
let id = query. id;
}


Can you help me writing the correct and complete script?
Thks
Bye

What kind of error do you get? Do you try this in preview mode or published mode? I believe you should test it in published mode and also do a console.log(query); so you can inspect that.

Hi, I’ve got it…

import wixLocation from ‘wix-location’;
offerta = wixLocation.query.id;

Much easier…
Thank’s a lot anyway

I have tried this but it is not working for me. The URL I am passing is https://abc.com/pSubDestination/31?ID=31

let myQuery = wixLocation.query;
var destId = myQuery.ID.toString();

Someone please help. And yes this is a dynamic page