programing tip

angularjs 1.6.0 (현재 최신) 경로가 작동하지 않음

itbloger 2020. 8. 25. 07:45
반응형

angularjs 1.6.0 (현재 최신) 경로가 작동하지 않음


Stackoverflow에서이 질문을 볼 것으로 예상했지만 그렇지 않았습니다. 분명히 나에게 매우 흔한 것처럼 보이는이 문제를 가진 유일한 사람은 나입니다.

작업중인 기본 프로젝트가 있지만 지금까지 수행 한 모든 작업이 옳은 것처럼 보이지만 경로가 작동하지 않는 것 같습니다.

index.html파일 에이 html 조각이 있습니다.

<html>
<head ng-app="myApp"> 
    <title>New project</title>
    <script src="https://code.angularjs.org/1.6.0/angular.min.js"></script>
    <script src="https://code.angularjs.org/1.6.0/angular-route.min.js"></script>

    <script src="app.js"></script>
</head>
<body>
    <a href="#/add-quote">Add Quote</a>
    <div ng-view ></div>
</body>
</html>

그리고 여기 내 app.js:

var app = angular.module('myApp', ['ngRoute']);


app.config(['$routeProvider', function ($routeProvider) {
    $routeProvider
        .when('/add-quote', {
            templateUrl: 'views/add_quote.html',
            controller: 'QuoteCtrl'
        })
        .otherwise({ redirectTo: '/' });
}]);

이제 페이지를 방문하면 다음과 같은 URL이 표시됩니다.

http : // localhost : 8000 / admin #! /

Add quote버튼을 클릭하면 다음과 같이 표시됩니다 .

http : // localhost : 8000 / admin #! / # % 2Fadd-quote

여기서 문제는 무엇일까요? 도와 줘서 고마워


#!href에서 hashbang 사용하면 됩니다.

 <a href="#!/add-quote">Add Quote</a>

aa077e8 로 인해 $ location 해시 뱅 URL에 사용되는 기본 해시 프리픽스가 빈 문자열 ( '')에서 뱅 ( '!')으로 변경되었습니다 .

실제로 해시 접두사를 사용하지 않으려면 응용 프로그램에 구성 블록을 추가하여 이전 동작을 복원 할 수 있습니다.

appModule.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);

자세한 내용은


내 말을 타서 미안하지만 ..이게 어떻게 풀렸어? 이것은 방대하고 파괴적인 버그입니다. @MiloTheGreat

참조 사양이 이미 공식적으로 지원 중단되었으므로 # 14202의 주요 변경 사항을 되돌려 야합니다. # 15715

피드백이 없기 때문에이 문제를 종료하겠습니다. 새로운 피드백을 제공 할 수 있으면 언제든지이 문제를 다시여십시오.

https://github.com/angular/angular.js/issues/15715#issuecomment-281785369


Simply include the ! into the href:

<body>
    <a href="#!/add-quote">Add Quote</a>
    <div ng-view ></div>
</body>

I couldn't get routing to work in 1.6.4 so I decided to use angular 1.5.11 and routing works fine although I needed to define all my routings in when(..) functions with trailing "/"

If sticking to an older version of angular is an option for you then consider it since it may save your nerves...

var app = angular.module("myApp", ["ngRoute"]);

app.config(function($routeProvider) {
$routeProvider
.when("/layoutandviewbox", {
    templateUrl : "views/layout-and-viewbox.html"
})
.when("/basicshapes", {
    templateUrl : "views/basic-shapes.html"
})
.when("/advancedshapes", {
    templateUrl : "views/advanced-shapes.html"
})
.when("/groups", {
    templateUrl : "views/groups.html"
})
.when("/transformations", {
    templateUrl : "views/transformations.html"
})
.when("/effects", {
    templateUrl : "views/effects.html"
})
.when("/", {
    templateUrl : "views/basic-shapes.html"
});
});

app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
  $locationProvider.hashPrefix('');
  $routeProvider
    .when('/add-quote', {
      templateUrl: 'views/add_quote.html',
      controller: 'QuoteCtrl'
    })
    .otherwise({ redirectTo: '/' });
}]);

Try this one might Help...

In html or view Page

 <body>
       <a href="#/Home.html">Home</a>
       <div ng-view></div>
 </body>

In Script Page

var app=angular
.module('myModule',['ngRoute'])
.config(function($routeProvider, $locationProvider) {
  $routeProvider
    .when('/Home', {
      templateUrl: 'FolderName/Home.html',
      controller: 'homeCtr'
    })
      $locationProvider.hashPrefix('');
     });

참고URL : https://stackoverflow.com/questions/41211875/angularjs-1-6-0-latest-now-routes-not-working

반응형