AngularJS 路由到静态文件
AngularJS routing to static file
我有一个简单的 angularjs
应用程序,其中 ngRoute
模块用于 html5Mode
中的路由。
我怎样才能在我的页面上有一个 link 到某个静态文件,而不让它被 angular 路由模块拦截?
示例如下:
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路由:
$routeProvider
.when('/', {
templateUrl: 'app/components/home/homeView.html',
controller: 'HomeController'
})
.when('/user', {
templateUrl: 'app/components/user/userView.html',
controller: 'UserController'
})
.otherwise({
redirectTo: '/'
});
当我点击 User link 时,我被路由到 localhost:8080/user
,我的控制器和模板工作正常。当我点击 users.html link 时,我被路由到主页,但我想调用静态 home.html
页面。
在 AngularJS docs 中,您有 3 个选项:
Html link rewriting
(...)
In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.
- Links that contain target element
Example: <a href="/ext/link?a=b" target="_self">link</a>
- Absolute links that go to a different 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>
您可能要查找的是第一个示例:
<a href="/users.html" target="_self">users.html</a>
我有一个简单的 angularjs
应用程序,其中 ngRoute
模块用于 html5Mode
中的路由。
我怎样才能在我的页面上有一个 link 到某个静态文件,而不让它被 angular 路由模块拦截?
示例如下:
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路由:
$routeProvider
.when('/', {
templateUrl: 'app/components/home/homeView.html',
controller: 'HomeController'
})
.when('/user', {
templateUrl: 'app/components/user/userView.html',
controller: 'UserController'
})
.otherwise({
redirectTo: '/'
});
当我点击 User link 时,我被路由到 localhost:8080/user
,我的控制器和模板工作正常。当我点击 users.html link 时,我被路由到主页,但我想调用静态 home.html
页面。
在 AngularJS docs 中,您有 3 个选项:
Html link rewriting
(...)
In cases like the following, links are not rewritten; instead, the browser will perform a full page reload to the original link.
- Links that contain target element
Example:<a href="/ext/link?a=b" target="_self">link</a>
- Absolute links that go to a different 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>
您可能要查找的是第一个示例:
<a href="/users.html" target="_self">users.html</a>