Difference between [removed].assign() and [removed].replace()

前端 未结 4 751
既然无缘
既然无缘 2020-11-28 03:56

What is the difference between window.location.assign() and window.location.replace(), when both redirect to a new page?

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:13

    1. location.assign():

      To assign route path by passing path into it. Assign will give you a history even after path was assigned.

      Usage Method: Value should be passed into it.

      Eg: location.assign("http://google.com")

    1. location.replace():

      It helps to replace path if you don't want to keep history. It won't give you a history once you replace its path.

      Usage Method: Value should be passed into it.

      Eg: location.replace("http://google.com")

提交回复
热议问题