Query Params not respected with variable ending path part

It seems that query Params don’t work with the anvil.server.route decorator when the last part of the path is a variable part:

Update: Also, in both cases where the path ends in a static string or in a variable one, if the response is an anvil.server.FormResponse object, then the query string is removed from the URL, making it difficult when reloading pages either manually or programatically.

This case has been added to the clone.

So this definitely seems like a bug.

Yes this is a known issue and is on our list as we continue to improve/enhance routing support.

2 Likes

For anyone who is wanting to make sure that their query params get added back when there’s a form response, you can do this in your form show event function:

from anvil.js.window import URL, history

def form_show(self, **event_args):
  current_url = URL(location.href)
    for param, value in query_params.items(): 
       current_url.searchParams.set(param, value)

    history.pushState({}, "", current_url)

And then whenever the query params are respected (which seems stable today, but it wasn’t yesterday (that is the first issue in this thread)), reloads will have the correct query params

1 Like

I realized today, that history.pushState adds another link in the browser history, so to add back the query Params, it’s better to use history.replaceState to just retain the accurate URL with the readded query parameters.

1 Like