AngularJS redirect controller and history back issue

64 Views Asked by At

I need help with external redirecting in AngularJS.

This is my route:

$routeProvider.when('/route1/', {
    template: html_externalRedirect,
    resolve: resolver(['core/controllers/ExternalRedirectController'])
});

This is my redirect controller:

define(['myApp',], function (myApp) {
   'use strict';
   myApp.lazy.controller('ExternalRedirectController', ['$location', '$window',
       function ($location, $window) {
          $window.location = baseUrl + $location.path();
   }]);
});

Redirect works successfully, but when I click 'back' browser button, it redirects me to 'not found' page. Seems like, records in window history are wrong. Could anyone help me solve this issue?

1

There are 1 best solutions below

1
Sarvesh Mahajan On

It may be because you didn't define the default route to $routeProvider. Please add either of two options to solve this problem:

  • .when("/", { template: html_externalRedirect })
  • otherwise({ template: html_externalRedirect });