AngularJS - Route - 별(*)을 경로로 일치시키는 방법
-
12-12-2019 - |
문제
리소스 뷰어 앱을 만들고 있는데 문제는 일치시키려고 했다는 것입니다. when("/!/:resourceUrl")
.
리소스 URL이 다음과 같으면 잘 작동합니다. /path
, 그런데 어떻게 하면 다음과 같은 것을 만들 수 있나요? /path/to/the/resource
.
얼마나 많은 길이 걸릴지 모르기 때문에 할 수 없습니다 .when("/!/:path1/:path2/:path3")
.
어떤 아이디어가 있나요?
해결책
각도 1.2부터 다음을 수행할 수 있습니다.
when("/!/:resourceUrl*")
http://code.angularjs.org/1.2.0/docs/api/ngRoute.$routeProvider
특히 문서에는 다음 예가 나와 있습니다.
예를 들어 다음과 같은 경로는 /color/:color/largecode/:largecode*\/edit
일치합니다 /color/brown/largecode
/code/with/slashs/edit
그리고 다음을 추출합니다:
color: brown
largecode: code/with/slashs
다른 팁
현재 Angularjs는 경로에서 정규 표현식을 지원하지 않습니다.
다음 링크를 확인하십시오 : https://github.com/angular/angular.js/문제 / 918 , https://github.com/angular/angular.js./ pull / 972
제휴하지 않습니다 StackOverflow