1

I have problem with window.history.pushState method. I'm on page https://localhost:1234/jobs. I want to add one parameter and hash to my url without reloading a page. I have a simple button to edit job:

<i class="fas fa-edit fa-fw"
   data-tooltip="tooltip"
   title="Edit this job"
   ng-click="goJobModal(job.id);$event.stopPropagation()"></i>

After pressing this, goJobModal should be executed with job.id

$scope.goJobModal = function(jobId) {
  if (jobId) {
    window.history.pushState(null, "Updating job", "/jobs/?jobId=" + jobId + "#update");
    console.log(window.location.href);
  } else {
    window.history.pushState(null, "Creating job", "/jobs#create");
  }
};

I placed a breakpoint in line with console.log to look what happens after pushState and I saw something iteresting for me. After $rootScope.$digest my url was cleared to https://localhost:1234/jobs. What should I do to successfully change my url?

Rick
  • 4,030
  • 9
  • 24
  • 35
Freezer
  • 21
  • 3
  • What are you trying to achive? You know there is a routing system in AngularJS? – MrWook Jul 16 '18 at 10:49
  • I need to change my url without reloading page. I read that, pushState method should change my url and dont reload page. This works for jobs#create, but when I'm trying to achieve the same effect for Updating job it doesn't work. – Freezer Jul 16 '18 at 10:55

0 Answers0