Search code examples
angularjsangularjs-routing

How can I get AngularJS go to another page onclick


I am using AngularJS routing, which is changing the template when I select a link. However, for the last page, I have a link that I want to go to another internal HTML page and not load a template view again. How can I do this?

So far I have tried a few options but here is what I have now.

app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){

  .when("/page-eight", {
    templateUrl : "views/page-eight.html",
    controller: 'primaryController'
  }) 
  .otherwise({
    templateUrl : "views/start.html"
  });
}]);

The above routing work, but as I have a link in my page-eight.html template as shown below, how can I force it to go to an internal page instead?

<a ng-href="internal-page.html" class="btn-solid">Go to Internal Page</a>

It seems that by clicking on the link above, this is connected to the 'otherwise' part of my route set up. Therefore, this doesn't go to my internal-page.html but loads in my start.html, not what I want.


Solution

  • I believe if you add target="_self" it will bypass the router.

    Also, your server side route handler needs to serve up the correct "non-SPA" content for that specific page, depending how you have it set up.