我是Angular的新手,我很喜欢学习js,但我试图在Spring Boot的前端运行Angular。默认情况下,Spring通常会呈现我的index.html页面,但当我尝试访问/ login页面时,出现404未找到错误。我已经尝试了几乎所有可以为模板url创建的url组合,但没有运气。因为我是Angular的新手,所以我无法确定这是Spring配置问题还是更简单的问题。SpringBoot + Angular ng-view问题
角控制器app.js:
var wishingWell = angular.module('wishingWell', [ 'ngRoute' ]);
wishingWell.config(function($routeProvider, $httpProvider) {
$routeProvider.when('/', {
templateUrl : 'static/home.html',
controller : 'home'
}).when('/login', {
templateUrl : 'static/login.html',
controller : 'navigation'
}).otherwise('/');
$httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
});
wishingWell.controller('home', function($scope, $http) {
$http.get('/resource/').success(function(data) {
$scope.greeting = data;
})
});
wishingWell.controller('navigation', function() {});
的index.html:
<!doctype html>
<html ng-app="wishingWell">
<head>
<meta charset="UTF-8"/>
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge"/>
<link rel="stylesheet" href="/css/normalize.css"/>
<link rel="stylesheet" href="/css/main.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-route.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.js" integrity="sha256-16cdPddA6VdVInumRGo6IbivbERE8p7CQR3HzTBuELA=" crossorigin="anonymous"></script>
<script src="/javascript/Angular/app.js"></script>
<title>Wishing Well</title>
</head>
<body ng-controller="home">
<nav class="nav">
<ul class="navback">
<li>
<a class="active" href="/">The Well</a>
</li>
<li>
<a href="/profile" >Profile</a>
</li>
<li>
<a href="/sign-up">Sign Up</a>
</li>
<li>
<a href="/login">Log In</a>
</li>
<li>
<a href="/logout">Sign Out</a>
</li>
</ul>
</nav>
<div ng-view></div>
</body>
</html>
文件夹结构:
任何想法?
这个404错误与angular没有任何关系。你能告诉我们你的url(localhost ...)和你的默认控制器吗? –