angularjs - ui-router:设置链接默认状态
问题描述
我想将默认状态设置为显示“仪表板”并在打开“127.0.0.1/mywebapp/”时激活“仪表板”链接。使用“$urlRouterProvider.otherwise('/dashboard');” 将完成这项工作,但我无法使用它,因为我将在第 404 页使用它。
这些是我的链接:
<ul class="nav-list">
<li class="nav-item" ui-sref-active="active">
<a ui-sref="dashboard" class="trans200">
<i class="icon fas fa-columns"></i>
<span class="text">Dashboard</span>
</a>
</li>
<li class="nav-item" ui-sref-active="active">
<a ui-sref="agents" class="trans200">
<i class="icon fas fa-user-tie"></i>
<span class="text">Agents</span>
</a>
</li>
<li class="nav-item" ui-sref-active="active">
<a ui-sref="projects" class="trans200">
<i class="icon fas fa-box-open"></i>
<span class="text">Projects</span>
</a>
</li>
<li class="nav-item" ui-sref-active="active">
<a ui-sref="supplies" class="trans200">
<i class="icon fas fa-parachute-box"></i>
<span class="text">Supplies</span>
</a>
</li>
</ul>
这是我当前的路由代码,但“默认”状态不会激活仪表板链接:
app.config(function($stateProvider,$locationProvider,$urlRouterProvider) {
$locationProvider.hashPrefix('');
$urlRouterProvider.otherwise('/404.htm');
$stateProvider
.state({
name:'default',
url:'',
templateUrl: './views/dashboard.htm',
controller:'dashboardCtrlr'
})
.state({
name: 'dashboard',
url: '/dashboard',
templateUrl: './views/dashboard.htm',
controller:'dashboardCtrlr'
})
.state({
name: 'projects',
url: '/projects',
templateUrl: './views/projects.htm',
controller:'projectsCtrlr'
})
.state({
name: 'supplies',
url: '/supplies',
templateUrl: './views/supplies.htm',
controller:'suppliesCtrlr'
})
.state({
name: 'agents',
abstract:true,
default:'.list',
url: '/agents',
templateUrl: './views/agents.htm'
})
// START OF AGENTS MODULE ROUTINGS
.state({
name: 'agents.list',
url: '',
templateUrl: './views/templates/agents/temp_agent_list.htm',
controller: 'agentsCtrlr'
})
.state({
name: 'agents.profile',
url: '/{username}',
templateUrl: './views/templates/agents/temp_agent_profile.htm',
controller: 'agentProfileCtrlr'
})
.state({
name: 'agents.create',
url: '/{username}',
templateUrl: './views/templates/agents/temp_agent_profile.htm',
controller: 'agentProfileCtrlr'
});
// END OF AGENTS MODULE ROUTINGS
});
解决方案
尝试使用运行块:
app.run(function($window, $state) {
if ($window.location.pathname === 'mywebapp/') {
$state.go('dashboard');
}
});
推荐阅读
- amazon-ec2 - 使用 AWS ECS 或 EKS 扩展 wowza 流引擎
- python - 多处理的并行性几乎没有减少时间
- reactjs - ReactJs 中的 Highcharts 网络图(强制有向图)
- python-3.x - Deserialize_keras_object 'module' 对象不可调用
- javascript - 参数类型字符串不能分配给 Cypress 中的参数类型 keyof Chainable...
- python - 将目录列表解析为嵌套字典
- oat++ - 如何将 C++ std::vector 设置为 OAT++ Vector
- php - 如果值已存在,则取消设置除最后一个子数组之外的所有子数组
- selenium - 即使出现错误,我如何保留测试用例?在机器人框架中
- android - 在 AOSP 中向系统应用授予对 /system/ 目录的读取权限