简体   繁体   English

Angular.js错误404路由

[英]Angular.js error 404 routing

I've got a simple angular.js app with two views: /login & /register. 我有一个简单的angular.js应用,具有两个视图:/ login和/ register。 My index.html looks this way: 我的index.html看起来是这样的:

... 
<body>
<ul class="menu">
  <li><a href="#/login">Login</a></li>
  <li><a href="#/register">Register</a></li>
</ul>
<div ng-view></div>
...(javascript inclusions)...

app.js app.js

var adventureApp = angular.module('ownAdventure', [
      'ngRoute',
      'ngCookies',
      'Login',
      'Register'
    ]);

adventureApp.config(['$routeProvider', '$locationProvider',
  function ($routeProvider){
    $routeProvider
    .when('/login', {
        controller: 'LoginController',
        templateUrl: '/login/login.view.html'
    })

    .when('/register', {
        controller: 'RegisterController',
        templateUrl: '/register/register.view.html'
    })

    .otherwise({ redirectTo: '/login' });
}]);

I've got both Login and Register modules in sepparate .js files, and added the LoginController and RegisterController accordingly in both files exactly the same. 我在单独的.js文件中同时具有LoginRegister模块,并分别在两个文件中完全相同地添加了LoginControllerRegisterController

login.controller.js (same with register): login.controller.js(与register相同):

'use strict';

var loginController = angular.module('Login', ['ngRoute', 'ngCookies']);

loginController.controller('LoginController', ['$scope',
  function($scope) {
    $scope.test = 'This is a simple test';
}]);

Both login/ and register/ folders are inside the app/ folder at the same level as app.js , therefore I cannot figure out why I constantly get the following error message: GET http://localhost:8000/login/login.view.html 404 (Not Found) login /register /文件夹都位于app /文件夹内,与app.js处于同一级别,因此我无法弄清为什么总是不断收到以下错误消息:GET http:// localhost:8000 / login / login.view .html 404(未找到)

Thank you in advance. 先感谢您。

"The error message : GET http://localhost:8000/login/login.view.html 404 (Not Found)" Implies that there is no login.view.html in the given folder hierarchy or it is not accessible at the given moment. “错误消息:GET http:// localhost:8000 / login / login.view.html 404(未找到)”意味着在给定的文件夹层次结构中没有login.view.html或在给定的文件夹中不可访问时刻。 As this error is related to your code, we will not bother about it. 由于此错误与您的代码有关,因此我们不会理会。 Coming to the folder hierarchy, what is your application name? 进入文件夹层次结构,您的应用程序名称是什么? (I believe it is "ownAdventure"). (我相信它是“ ownAdventure”)。 So the index.html page loads at "localhost:8080/ownAdventure/". 因此index.html页的加载位置为“ localhost:8080 / ownAdventure /”。 You mentioned "Both login/ and register/ folders are inside the app/ folder at the same level as app.js" it doesn't help much, because you didn't mention the folder hierarchy for app.js. 您提到“ login /和register /文件夹都在app /文件夹中,与app.js处于同一级别”,这没有多大帮助,因为您没有提到app.js的文件夹层次结构。 I assume that app.js is right under your app folder. 我认为app.js就在您的应用文件夹下。

In that case "localhost:8080/ownAdventure/login/login.view.html" will be accessible. 在这种情况下,将可以访问“ localhost:8080 / ownAdventure / login / login.view.html”。

Note: "templateUrl: '/login/login.view.html'" the path provided here is relative to the parent path, not to the file from which it is called(in this case app.js). 注意:“ templateUrl:'/ login / login.view.html'”此处提供的路径是相对于父路径的,而不是相对于其被调用的文件(在本例中为app.js)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM