컨텍스트 사용자는 자신의 페이지를 식별하는 고유 URL slug로 등록 할 수 있습니다. 'http://example.com/slug'.MEANJS : URL에 대한 db 확인 및 동적 각도 상태로의 경로
현재 상태 내 Express.js 파일에서 , 나는 성공적으로 슬러그 사용자에 존재하는지 내 데이터베이스를 확인, 다음을 활용하는 'http://example.com/#!/slug'에 'http://example.com/slug'에서 사용자 리디렉션 Angular의 라우팅 경로입니다.
그러나 Angular를 사용하면 라우터 파일에서 $ http 또는 $ location 서비스를 사용할 수 없습니다 (자세한 내용은 this Stack Overflow explanation 참조).
욕망 기본적으로 제가하고 싶은 것은 경로가 그렇지 않은 경우에 유효한 슬러그가 발견, 또는 가정하는 '기본'보기로 사용자입니다. 어떤 제안이라도 대단히 감사 할 것입니다.
참고로, 내 module.config 코드는 여기에서 찾을 수 있습니다 (I 사용할 '기본'상태가 '검색'이다) :
core.client.routes.js
내가하고 싶은 무엇'use strict';
// Setting up route
angular.module('core').config(['$stateProvider', '$urlRouterProvider',
function($stateProvider, $urlRouterProvider) {
// Redirect to home when route not found.
$urlRouterProvider.otherwise('/');
// Home state routing
$stateProvider.
state('home', {
url: '/',
templateUrl: 'modules/core/views/home.client.view.html'
}).
state('search', {
url: '/search',
templateUrl: 'modules/core/views/search.client.view.html'
});
}
]);
는 , ...이 같은 것입니다
'use strict';
// Setting up route
angular.module('core').config(['$stateProvider', '$urlRouterProvider', '$http', '$location',
function($stateProvider, $urlRouterProvider, $http, $location) {
// Get current slug, assign to json.
var slug = $location.path();
var data = {
link: slug
};
// Check db for slug
$http.post('/my/post/route', data).success(function(response) {
// Found slug in db
}).error(function(response) {
// Route to home
$location.path('/');
});
// Home state routing
$stateProvider.
state('home', {
url: '/',
templateUrl: 'modules/core/views/home.client.view.html'
}).
state('search', {
// Set URL to slug
url: '/' + slug,
templateUrl: 'modules/core/views/search.client.view.html'
});
}
]);
응답 해 주셔서 감사합니다. Jeff. 귀하의 제안은 내가하고있는 문제가되었던 몇 가지 사항을 개념화하는 데 도움이되었습니다 (AngularJS에 처음 온 것은 당연한 것입니까?). 나는 크게 단순화했고 단지 내 컨트롤러에 내 $ http 요청을 넣었습니다. 또한 사용자가 'example.com/#!/slug'에서 'example.com/#!/search/slug'로 라우트 된 URL을 변경했습니다 (이후 # /! /! 같은 다른 모든 페이지를 덮어 썼기 때문에) 로그인 등). 다시 도움을 주셔서 감사합니다. – aikorei
이것은 또한 훌륭한 대안입니다 : http://stackoverflow.com/questions/24727042/angularjs-ui-router-how-to-configure-dynamic-views –