Remove all URL hashes when redirecting with go()

I have some code that redirects the user to a confirmation page after is sent successfully.

There, I use the following code:


I use a hash in the action url of my form:

<form novalidate action="/en/<current-page>#newsletter-footer" method="POST">

This ensures, the page scrolls to the form in case it was marked as invalid by the server.

Now the issue is, the redirect with go() still includes the hash. Which makes it directly scroll to the form in the footer on the confirmation page.

How do I make a “clean” redirect without the hash being applied? Do I need to use visit() or any other function?

I’m not sure if I get your question?

I believed ->url() never sets fragments? :thinking:
IIRC you can add fragments in the go() helper like this: go($somePage->url() . '#somefragment');.

If you want to explicitly remove the fragment; you can use an url helper like this: go(Url::stripFragment($someUrlWithFragment));