我试图在我的Angularjs应用程序中美化网址,但我的成功有限 - 我可以达到"/"
路线,但那就是它,{{ 1}}无法访问。
注意:项目位于(
"/about"
)。
localhost/myngapp
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="myngapp">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular-route.js"></script>
<script type="text/javascript" src="http://localhost/myngapp/public/js/app.js"></script>
</head>
<body data-ng-app="demoApp">
<div data-ng-view></div>
</body>
</html>
angular.module('demoApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
controller: 'homeCtrl',
templateUrl: 'home.html'
})
.when('/about', {
controller: 'aboutCtrl',
templateUrl: 'about.html'
})
.otherwise({ redirectTo: '/' });
})
.controller('homeCtrl', function ($scope) {
$scope.title = 'This is, the App!';
})
.controller('aboutCtrl', function ($scope) {
$scope.title = 'About App!';
});
<ifModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
</ifModule>
)
答案 0 :(得分:1)
<base>
是罪魁祸首<head>
<script>
document.write('<base href="' + document.location + '" />');
</script>
</head>
OR
<head>
<base href="/myngapp/">
</head>