Javascript AngularJS UI路由器根范围段塞路由
我正在尝试为根作用域实现一个路由,如Javascript AngularJS UI路由器根范围段塞路由,javascript,angularjs,angular-ui-router,slug,Javascript,Angularjs,Angular Ui Router,Slug,我正在尝试为根作用域实现一个路由,如 /#/profile-1 /#/profile-2 /#/developer-name 我猜你明白了。我正在使用AngularJS 1.4和UI路由器0.2.15 我的问题是现在我有了这条路线,这是我路线顺序中的最后一条: (function () { 'use strict'; angular .module('bs3Prototype') .config(routerConfig); /**
/#/profile-1
/#/profile-2
/#/developer-name
我猜你明白了。我正在使用AngularJS 1.4和UI路由器0.2.15
我的问题是现在我有了这条路线,这是我路线顺序中的最后一条:
(function () {
'use strict';
angular
.module('bs3Prototype')
.config(routerConfig);
/** @ngInject */
function routerConfig($stateProvider, $urlRouterProvider) {
$stateProvider.
state('home', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainController',
controllerAs: 'main'
}).
state('profiles', {
url: '/profiles',
templateUrl: 'app/profiles/profiles_listing.html',
controller: 'ProfilesController',
controllerAs: 'profiles'
}).
state('search', {
url: '/search',
templateUrl: 'app/search/search.html',
controller: 'SearchController',
//controllerAs: 'search',
reloadOnSearch: false,
resolve: {
profileCategories: function(profileCategoriesService) {
return profileCategoriesService.index();
},
jobCategories: function(staticListsService) {
return staticListsService.getList('jobTypes');
},
agendaCategories: function(agendaCategoriesService) {
return agendaCategoriesService.index();
},
buildingTypes: function(buildingTypesService) {
return buildingTypesService.index();
}
}
}).
state('profile', {
url: '/:profileSlug',
templateUrl: 'app/profile/profile_view.html',
controller: 'ProfileController',
controllerAs: 'profile',
resolve: {
profile: function (profilesSerivce, $stateParams) {
console.log(profilesSerivce.getProfile($stateParams.profileSlug));
return profilesSerivce.getProfile($stateParams.profileSlug);
}
}
});
$urlRouterProvider.otherwise('/');
}
})();
在另一个视图“我的搜索结果”中,我使用以下URL:
<a ui-sref="profile({profileSlug: result.slug})">Profile: {{result.profile_title.profile_title_default}} (ID: {{result.id}})</a>
console.log()调用的输出如下:
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
index.route.js:19 encode
index.route.js:20 architekturhalle
index.route.js:36 is
index.route.js:37 architekturhalle
我真的不明白为什么不调用解码
我只将我的个人资料路线更改为:
state('profile', {
url: '/{profileSlug:profileSlug}',
templateUrl: 'app/profile/profile_view.html',
//controller: 'ProfileController',
controller: function() { alert('TEST'); },
//controllerAs: 'profile',
resolve: {
profile: function (profilesSerivce, $stateParams) {
console.log(profilesSerivce.getProfile($stateParams.profileSlug));
return profilesSerivce.getProfile($stateParams.profileSlug);
}
}
});
多次遇到这种情况,我以前对其进行故障诊断的方式是:
var myApp=angular.module(“appModuleName”,['ui.router']);
var urlinfo=“/index.html”;
myApp.config(函数($stateProvider,$urlRouterProvider){
$stateProvider.state('dashboard'{
url:“/settings”,
templateUrl:'templates/settings.html'
})
.陈述(“客户”{
url:“/profile”,
templateUrl:'templates/profile.html',
控制器:'customerDetailsController'
})
.state('admin'{
url:“/account”,
templateUrl:'templates/account.html',
控制器:'adminDetailsController'
});
$urlRouterProvider。否则('/settings');
});
控制器(“customerDetailsController”,函数($scope){
$rootScope.customerDetails={名称:'Venkat',职业:'software'};
});
控制器(“adminDetailsController”,函数($scope){
var adminDetailsList=[{名称:'Venkat',职业:'admin'},
{姓名:'nishita',职业:'Account'},
{姓名:'laxmi',职业:'FINCE'}];
$scope.adminDetails=adminDetailsList;
});代码>
/*!
*启动引导-简单侧边栏(http://startbootstrap.com/)
*版权所有2013-2016启动引导
*麻省理工学院授权(https://github.com/BlackrockDigital/startbootstrap/blob/gh-pages/LICENSE)
*/
身体{
溢出x:隐藏;
}
/*切换样式*/
#包装纸{
左侧填充:0;
-webkit过渡:所有0.5s轻松;
-moz过渡:所有0.5s轻松;
-o型过渡:所有0.5s的轻松度;
过渡:所有0.5s缓解;
}
#包装器。切换{
左侧填充:250px;
}
#边栏包装{
z指数:1000;
位置:固定;
左:250px;
宽度:0;
身高:100%;
左边距:-250px;
溢出y:自动;
背景:#000;
-webkit过渡:所有0.5s轻松;
-moz过渡:所有0.5s轻松;
-o型过渡:所有0.5s的轻松度;
过渡:所有0.5s缓解;
}
#wrapper.toggled#侧栏包装器{
宽度:250px;
}
#页面内容包装器{
宽度:100%;
位置:绝对位置;
填充:15px;
}
#wrapper.toggled#页面内容包装器{
位置:绝对位置;
右边距:-250px;
}
/*边栏样式*/
.侧边栏导航{
位置:绝对位置;
排名:0;
宽度:250px;
保证金:0;
填充:0;
列表样式:无;
}
.侧边栏导航李{
文本缩进:20px;
线高:40px;
}
.侧边栏导航李a{
显示:块;
文字装饰:无;
颜色:#999999;
}
.侧边栏导航李a:悬停{
文字装饰:无;
颜色:#fff;
背景:rgba(255255,0.2);
}
.侧边栏导航李a:激活,
.侧边栏导航李a:焦点{
文字装饰:无;
}
.sidebar nav>.sidebar品牌{
高度:65px;
字号:18px;
线高:60px;
}
.sidebar nav>.sidebar品牌a{
颜色:#999999;
}
.sidebar nav>.sidebar品牌a:悬停{
颜色:#fff;
背景:无;
}
@介质(最小宽度:768px){
#包装纸{
左侧填充:250px;
}
#包装器。切换{
左侧填充:0;
}
#边栏包装{
宽度:250px;
}
#wrapper.toggled#侧栏包装器{
宽度:0;
}
#页面内容包装器{
填充:20px;
位置:相对位置;
}
#wrapper.toggled#页面内容包装器{
位置:相对位置;
右边距:0;
}
}
欢迎光临
表,th,td{
边框:1px纯灰;
边界塌陷:塌陷;
填充物:5px;
}
表tr:第n个子项(奇数){
背景色:#f1f1;
}
表tr:第n个子项(偶数){
背景色:#ffffff;
}
-
-
仪表板
-
顾客
-
管理
如果您直接导航到URL会发生什么?没有,它会加载布局,但不会加载内部视图,console.log()不会被触发。啊,对了,我知道为什么。您需要有类似于profile/:profileSlug
的URL。如果这不起作用,您是否可以共享在尝试导航到该URL时发出的网络请求?最后,您是否有任何JS错误?好的,但是我的URL将变成/#/profile/
,但是我需要它在URL的根级别上,正如标题所说的那样。您是否有可能创建一个Plnkr?我可以试着调试它。您还可以监听广播事件,以查看触发了哪些事件。您可以在本备忘单(第5页)上看到播放的事件列表
state('profile', {
url: '/{profileSlug:profileSlug}',
templateUrl: 'app/profile/profile_view.html',
//controller: 'ProfileController',
controller: function() { alert('TEST'); },
//controllerAs: 'profile',
resolve: {
profile: function (profilesSerivce, $stateParams) {
console.log(profilesSerivce.getProfile($stateParams.profileSlug));
return profilesSerivce.getProfile($stateParams.profileSlug);
}
}
});