Remove query param from url

blueFast picture blueFast · May 27, 2019 · Viewed 16.2k times · Source

I have the following URL:

http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860

And I want to redirect to:

http://my.site#/homepage

I do that with:

import { push } from 'react-router-redux'

...

dispatch(push('/homepage'))

But react takes me to:

http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860#/homepage

How can I tell React to drop the query param in the browser's address bar without reloading the application?

Answer

uyghurbeg picture uyghurbeg · Oct 28, 2019

With Regular Expression maybe this solution is easier for you:

  var oldURL = 'http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860'
  var newURL = /(http(s?).+)(\?.+)/.exec(oldDomain)[1] + 'homepage'

You can use newURL in your project.