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이 표시됩니다.
Add 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
'programing tip' 카테고리의 다른 글
“요청을 처리하는 동안 예외가 발생했습니다. (0) | 2020.08.25 |
---|---|
iOS 10-카메라, 마이크 및 사진 라이브러리의 권한 요청 변경으로 인해 응용 프로그램이 중단됨 (0) | 2020.08.25 |
Subversion / TortoiseSVN에서 삭제 된 폴더를 "삭제 취소"하는 방법은 무엇입니까? (0) | 2020.08.25 |
Ruby에서 재귀 적으로 디렉토리를 만드는 방법은 무엇입니까? (0) | 2020.08.25 |
두 해시를 어떻게 비교합니까? (0) | 2020.08.25 |