1

I am currently on the following endpoint.

http://www.mydomaintest.com/first_path?param1=1&param2=2

I am looking to change this to following where the path is now /new_path:

http://www.mydomaintest.com/new_path?param1=1&param2=2

Currently performing the following command which does change the path, but it removes the query params.

window.location.href = '/new_path';

How can I change the path but still retain the query params?

1 Answer 1

4

Instead of changing href just change the pathname, like this:

window.location.pathname = '/new_path';

It will update the URL and will retain the query params.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.