我有嵌套视图的角度Js App,我面临的问题是当我在嵌套视图中单击F5时它会被重定向到默认状态,我想保持当前状态。
我可以理解重新加载它转到父ui-view加载依赖项,然后它重定向到我已映射的默认视图但如何将其重定向到初始视图而不是默认视图。
routes.js
$urlRouterProvider.otherwise('/dashboard');
.state('dashboard', {
url: '/dashboard',
},
views: {
// the main template will be placed here (relatively named)
'': {
templateUrl: 'views/dashboard.html',
controller: 'dashboardIndexController'
},
'headbar@dashboard': {
templateUrl: 'views/headbar.html',
controller: 'headbarController'
}
}
})
.state('dashboard.home', {
url: '/home',
templateUrl: 'views/dashboard.home.html',
controller: 'dashboardController',
})
.state('dashboard.campaigns', {
url: '/campaigns',
templateUrl: 'views/campaigns.html',
controller: 'showCampaign',
})
仪表板控制器
$state.go('dashboard.home');
当我点击广告系列上的刷新状态时,它会重定向回dashboard.home,它应该按照代码进行操作但是如何在重新加载后保留广告系列或其他嵌套状态。
答案 0 :(得分:0)
成功登陆页面后,将当前页面名称/网址存储在localStorage
中window.localStorage.setItem('currentPage', window.location.pathname):
初始化之后,在重定向到主页之前,重定向到之前存储的url:
if (window.localStorage.getItem('currentPage')
$state.go(window.localStorage.getItem('currentPage'));
else
// go to home page normally