AngularJS routing to a static file

I have a simple angularjs application, with the ngRoute module for routing in html5Mode . How can I have a link to some static file on my page so that it is not intercepted by the angular routing module?

Here is an example:

HTML:

  <head> <base href='/'></base> </head> <body ng-app="crudApp"> <a href="/">Home</a> <a href="/user">User</a> <a href="/users.html">users.html</a> <div ng-view></div> 

JS routing:

 $routeProvider .when('/', { templateUrl: 'app/components/home/homeView.html', controller: 'HomeController' }) .when('/user', { templateUrl: 'app/components/user/userView.html', controller: 'UserController' }) .otherwise({ redirectTo: '/' }); 

When I click on the User link, I am redirected to localhost:8080/user , and my controller and template work fine. When I click on the users.html link, they direct me home, but I want to call the static home.html page.

+5
source share
1 answer

In AngularJS Docs , you have 3 options:

Rewriting HTML Links

(...)

In the following cases, the links are not rewritten; instead, the browser will reload the page completely at the original link.

  • Links containing the target element
    Example: <a href="/ext/link?a=b" target="_self">link</a>
  • Absolute links that go to another domain
    Example: <a href="http://angularjs.org/">link</a>
  • Links starting with '/' that lead to a different base path
    Example: <a href="/not-my-base/link">link</a>

What you might be looking for is the first example:

 <a href="/users.html" target="_self">users.html</a> 
+17
source

All Articles