# Manipulate URL Queries

**URL:** <https://community.weweb.io/t/manipulate-url-queries/17156>\
**Category:** How do I?\
**Created:** [March 13, 2025, 7:32pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156 "2025-03-13T19:32:18Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 13, 2025, 7:32pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/1 "2025-03-13T19:32:18Z")

</div>

I have a table. When you click on a table row, it opens the details of that row in a modal. Up until now I’ve set a `selected_row` variable onClick and passed that variable to the modal to pass the data.

Fast forward to today, I am trying to deep link to a modal. My first attempt has been to append `id=123` to the URL, then on Page Load, check if the URL query exist, and if so fetch the object for that ID, to pass to the modal, and open the modal. I’ve got all that working fine, but what I can’t seem to figure out is how to clear that URL query when closing the modal.

What I’ve tried:

1. Custom javascript which deletes the query – this works in isolation (pressing the test button on the action) but doesnt nothing when triggering the workflow in Preview. This feels like the best path forward, if only I could get it to execute in practice.
2. Navigate to a page – this shouldnt really be necessary since the page is in the background of the modal ; still I tried to “delete the query” by both no setting one as well as setting it as an empty array.
3. I finally truend to WeWeb AI, which suggested something similar to 2, but instead of navigating to a Page, navigating to a Path; otherwise all the same. Nothing.
4. I asked Claude, after providing all this context and it recommended to custom javascript that forces the page to refresh, which accomplishes what I want, but at the expense of UX  
.5. I guess I could set the query to empty, keeping the query key there, but that doesn’t feel all that elegant.

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [March 13, 2025, 9:27pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/2 "2025-03-13T21:27:36Z")

</div>

Have you tried using reset action or changing the query via change variable value to null or something similar?

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 13, 2025, 10:11pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/3 "2025-03-13T22:11:15Z")

</div>

Thanks for the quick response. Not sure I follow—Im not using variables here so how would I find the “variable” in either the Change Variable Value or Reset Variable Value actions to modify the query? I found a solution, but curious if your path reveals a better way to do this.

The following code is what I was referring to in #1. Since this worked when pressing the test button in the Custom Javascript ation (research suggested the routing behaves differently in Editor) I took a chance and deployed it. To my surprise, it actually worked as expected.

```auto
const url = new URL(window.location.href);
url.searchParams.delete("id");
window.history.replaceState({}, "", url.toString());

```

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 13, 2025, 10:35pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/4 "2025-03-13T22:35:29Z")

</div>

Now that I have this working, I’ve moved onto the next phase of the feature—if a user is not authenticated then we need to store the url (path and queries) \> direct to sign in \> and then redirect to the respective path + queries.

When a user lands on a page and is unauthenticated…I store the `path` and the `queries` of the original URL in a variable \> redirect to the 2FA sign in flow \> and upon verifying the code trigger the following action.

Tip: for any future readers, despite the queries natively being stored as an object, the queries input expects an array in the following format `[{"name":"key", "value":"value"},{"name":"key", "value":"value"}]`. This took me a while to get to this point.

So I’ve gotten to the point where my dynamically bound Queries are working, and I can hardcode the path, eg “offers” —the logic in the screenshot below successfully redirects to the proper page with the queries appended—but as soon as I bind the Path to the “path” value in my variable it wigs out. Obviously the path in the Editor is some random alphanumeric sequence, so I took a chance and deployed it to Production to rest, wondering if this too was victim to the Editor routing, but no luck so I had to rollback.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/3/3b7bf0a6b1bdfcbca3e4f6ff8274c875a0cae344.png)

---

<div class="post-metadata">

**Author:** ![DanielL](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/daniell/32/13398_2.png) [@DanielL](https://community.weweb.io/u/DanielL)\
**Post date:** [March 15, 2025, 7:01am UTC](https://community.weweb.io/t/manipulate-url-queries/17156/5 "2025-03-15T07:01:34Z")

</div>

Hi @archenia_jsanchez nice workaround. Could you please elaborate why you had to use JavaScript for this? How are the no-code query variables not satisfactory? [Intro to variables | WeWeb Documentation](https://docs.weweb.io/data/intro-to-variables.html#query)

You can change the query using the Change a variable value action or reset it.

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 17, 2025, 1:51pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/6 "2025-03-17T13:51:45Z")

</div>

I’ll have to look into the query\*\* variable—I’ve never dug into it in the past, probably because I’ve never had a legit use case. Also, after watching the video I wonder if all the `selected_*` variables that I’ve created should be reconsidered through this lens. I’ll have to give it a try now that I know what that variable type is.

\*\* I’ve seen this variable in the drop down list but it just wasn’t intuitive to me—“query string” or “query parameter” is the label I think of—and as such never had the feeling that this was something I needed to use or research. 🤦

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 17, 2025, 5:18pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/7 "2025-03-17T17:18:46Z")

</div>

Aww, heck. Reporting back to share that the query variable seems to be doing the trick! I now understand what you were hinting at, @Broberto — resetting the query variable on modal close automatically removes the query string from the URL. I wish I would have discovered/learned this much earlier and could’ve avoided a lot of headache.

Now to chip away at the unauthenticated experience…

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 17, 2025, 6:51pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/8 "2025-03-17T18:51:11Z")

</div>

@DanielL might you have some advice on how to handle the unauthenticated experience?

For example, a user clicks on www [dot] archenia [dot] com/offers?tab=available&offer\_id=123 only to find out they are unauthenticated. The way I am handling this is:

1. on page load of the Budgets page, before fetching collections, I check to see if the user is authenticated. If not, I store the url path in a text variable and the tab and offer\_id in individual query variables all in local storage
2. The app redirects to the sign in page, based on my experience testing in Production with “?\_source=/Budgets” injected into the URL
3. I go through the OTP flow and upon clicking “verify code” I run a workflow that checks to see if that redirect path is not null. If it is null, then navigate to the home page, otherwise navigate to the redirect page. I’m attempting to do this by mapping the Path to my path variable and hardcoding the query parameters (see screenshot below) but am not having any success; in case you are wondering, I am hardcoding the query parameters because it’s unclear how to store all queries in the originating URL, and then loop through them all and add them to the query parameters.

\*\* where I am having trouble is, ideally the app can manage redirecting _any_ inbound URL so the page/path and the queries need to be smart. I’ve only been successful when I’ve hardcoded `Page = Budgets`. I was hopeful that the path would work in Production because the routing is more straightforward but that doesn’t appear to be the case.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/a/ade1301755c7ce2f04a5972a5464ee31f2bf9fd3.png)

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 18, 2025, 6:47pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/9 "2025-03-18T18:47:30Z")

</div>

@flo @Matthew_S thanks for the time in Office Hours. I took the advice and have the following:

1. On page load, if unauthenticated, set `redirect_path` to `window.location.pathname.substring(1) + window.location.search;` to
2. redirect to authentication
3. if `textLenght(redirect_path)>0` then “navigate to w/ path” ..

it looks like the Editor is replacing part of the URL with (or adding to the beginning) “ww\_front”. I want to blindly trust that this will work as expected in Production, but right now in Editor its not behaving as desired. Is there anything I can do to solve for this?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/7/76683d9ab4299987a64a94d6cf54c770b37ab451.png)

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 18, 2025, 7:00pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/10 "2025-03-18T19:00:21Z")

</div>

Immediately following up to my own thread, I stepped through the code and the above was causing an error.

I manually updated the variable from the Log by

1. first, replacing `ww_front` with what I think is my Editor UID or something `8f650259-b761-40cb-954f-dd4754073715` (which didn’t work); and then
2. then, replacing the entire path Editor path `/8f650259-b761-40cb-954f-dd4754073715/010403a8-eea7-4468-b059-002734aabcc0` with `Current page.paths.default` which is `budgets` (this is what solved it)

So, I’ve gone back to where I am setting `redirect_path` variable and concatenating `Current page.path.default` + `window.location.search`

This FINALLY works as desired, and think I’m going to check this off as done. Still, what I thought was the obvious solution didn’t work, and what I have feels like its bandaged together until it worked—which I just am waiting for something to break. Can y’all provide some feedback on my solution?

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 18, 2025, 7:37pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/11 "2025-03-18T19:37:56Z")

</div>

CORRECTION.

The solution does not work in Production. It appears that Production and Editor do not behave the same when it comes to configuring Private Access for pages.

 ![Screenshot 2025-03-18 at 3.19.22 PM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/4/4d1f644655055407ac989329f817c9668ae59f39.png)

I have all restricted pages set to “authenticated users” only. It appears that in Production, the page never loads and so any App Load or Page Load workflows that I’ve built (at least at the page level) are completely ignored. I’ve validated this by changing this setting \> deploying \> and watching the local storage variables in the Inspector console. I can see that the local storage variable is being set ONLY when the page is set to “Everybody.” I’ve also moved the workflow from the page level to the app level.

Unfortunately in doing so—changing the access level regardless of where I place the workflow—the Budget page loads for a brief second and then redirects to Sign In which doesn’t look elegant. Surely there has to be a better way to do this.

---

<div class="post-metadata">

**Author:** ![matt-thrive](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@matt-thrive](https://community.weweb.io/u/matt-thrive)\
**Post date:** [March 19, 2025, 5:22am UTC](https://community.weweb.io/t/manipulate-url-queries/17156/12 "2025-03-19T05:22:25Z")

</div>

This is quite the thread. A bit beyond my understanding but I’m hoping to accomplish a similar outcome.

Clicking on a Row, opens a Modal of an item ID. It seems you had to accomplish passing that ID in the URL via Javascript as a URL parameter?

---

<div class="post-metadata">

**Author:** ![Matthew\_S](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/matthew_s/32/13342_2.png) [@Matthew\_S](https://community.weweb.io/u/Matthew_S)\
**Post date:** [March 19, 2025, 10:48am UTC](https://community.weweb.io/t/manipulate-url-queries/17156/13 "2025-03-19T10:48:07Z")

</div>

Hopefully this should help:

pt 1: [https://screen.studio/share/OhwhVuhv](https://screen.studio/share/OhwhVuhv)

pt 2: [https://screen.studio/share/SYXGaihn](https://screen.studio/share/SYXGaihn)

I recorded the first part, then saw the issues you were having with the restricted access pages 😁

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 19, 2025, 3:05pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/14 "2025-03-19T15:05:27Z")

</div>

@matt-thrive

Previously, I had a variable, of type object, called `selected_offer`. When a user clicked a row, I set this variable to `data.item` (the data bound to the row via the repeating items from the collection). This way all of the row’s data could be referenced in the modal.

Now, what I am doing is, I have a new variable called `offer_id`, of type query. When a user clicks on a row i am setting `offer_id` to `data.item.id` which _automatically_ appends “offer\_id=[row id]” to the URL. This allows me to do the external deep linking—I’m not sure it’s necessary otherwise. For now, I am still creating the `selected_offer` object too as I was doing previously to pass all that data which is already present in the table to the modal, but I suppose you could simply take the id and fetch the data on modal open for various reasons.

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 19, 2025, 7:31pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/15 "2025-03-19T19:31:25Z")

</div>

Thanks for the videos. Unfortunately I’ve been poking at my configuration, and unless I do some overhaul I’m concluding this just isn’t possible.

1. your solution uses a product detail _page_, which with it has its own url parameter, eg `product/12`, whereas I have a list page with an offer detail _modal_, eg `budgets?offer_id=123`
2. the Supabase unauthentication redirect only passes the path, no query strings, so in your solution `_source` is properly set to the `product/12` whereas in mine, its still only setting to `budgets`. I suppose I could change the modal to a page, but I’m not too keen on that at this moment.
3. Since the redirect is happening automatically with the Supabase Auth plugin, I dont see a way to correct `_source` before it redirects to Sign In. Unless I’m mistaken, no workflows will trigger before redirecting from `budgets?offer_id=123` to `sign-in`
4. If I were able to get the query strings, I think I understand how I can either a) store that variable in local storage to redirect after Verify OTP Code, or b) I imagine I could Navigate to Verify OTP Code page w/ the `_source` still attached to the URL

---

<div class="post-metadata">

**Author:** ![Matthew\_S](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/matthew_s/32/13342_2.png) [@Matthew\_S](https://community.weweb.io/u/Matthew_S)\
**Post date:** [March 20, 2025, 10:53am UTC](https://community.weweb.io/t/manipulate-url-queries/17156/16 "2025-03-20T10:53:51Z")

</div>

Ok, I think I fully understand now.

Here is a more manual approach I think you can work with: [https://screen.studio/share/IITvcZtw](https://screen.studio/share/IITvcZtw)

---

<div class="post-metadata">

**Author:** ![archenia\_jsanchez](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/archenia_jsanchez/32/8656_2.png) [@archenia\_jsanchez](https://community.weweb.io/u/archenia_jsanchez)\
**Post date:** [March 20, 2025, 1:52pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/17 "2025-03-20T13:52:42Z")

</div>

Thanks, Matthew! This all makes sense. I had explored something similarly before—public page with a workflow that controls the unauthenticated redirect—but I failed to include the conditional rendering and so I moved on from that solution shortly after seeing my Budgets page load for a moment before redirecting and not thinking to troubleshoot _that_ part. Thanks for all the support 🤜 🤛

\*\* P.S. I didn’t know Screen Studio now does sharing hosted videos! Looks like I’ll have to upgrade my license to unlock that feature.

---

<div class="post-metadata">

**Author:** ![joseph](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/joseph/32/11340_2.png) [@joseph](https://community.weweb.io/u/joseph)\
**Post date:** [June 15, 2025, 1:08pm UTC](https://community.weweb.io/t/manipulate-url-queries/17156/18 "2025-06-15T13:08:29Z")

</div>

Thanks for the video! I’m currently adding defenses to my app, and I enjoy walking through the video versus reading snippets . This makes perfect sense.

@archenia_jsanchez I appreciate your question. Regarding defenses, during my alpha testing, I recently added a user/domain check to allow only a specific set of users to register. Then, I extended the functions so that I can ban specific email addresses.

Not sure if you’ve already addressed this, but it could be a good topic.
