Add url part to main url using angularjs or javascript

I have a url as shown below.

http://localhost:12534/urlpart1/urlpart2?querystring=140

      

So I need to replace "urlpart2" with "urlpart3" using javascript or anugularjs. How can I do that. I can get the whole url using:

  var urlPath = window.location.href;

      

Any help would be much appreciated.

+3


source to share


1 answer


If you just need to replace a specific substring urlpart2

, you can go with a simple method replace

:



var urlPath = window.location.href;
var newUrlPath = urlPath.replace('urlpart2', 'urlpart3');

      

+3


source







All Articles