angularjs - '/:routeparams' 正在覆盖 angularjs 中的其他路由
问题描述
app.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'junk.html',
})
. .when('/:pageuniqueid', {
templateUrl : 'page.html',
})
// route for the about page
.when('/first', {
templateUrl : 'first.html',
})
// route for the contact page
.when('/second', {
templateUrl : 'second.html',
});
});
如果我在 URL 中键入“example.com/first”,那么我得到的不是 first.html,而是 page.html。我正在实现用户可以在基本 URL 之后使用其动态 pageid 直接访问的页面。只有当它与其他路由不匹配时,我才想获取 page.html。有没有办法做到这一点?
解决方案
路由定义的顺序很重要。
如果您在 '/:pageuniqueid' 之前定义 '/first' 路由,它应该可以工作。
角度路由器在第一次匹配后停止评估路由。
因此,为了将 page.html 作为后备,您应该将其作为列表中的最后一个条目。
推荐阅读
- c - 在 C 中每行右侧的每第 n 个位置添加一个逗号
- google-cloud-sql - 不使用 DB 但使用 Cloud SQL (PostgreSQL 12) 存储增加 ~17M/5Min
- python - 删除最小数量的重叠圆?
- mongodb - 有没有办法只更新已发送的内容?
- node.js - 如何使用 Nodejs (API) 获取 S3 中的所有图像。我没有钥匙
- c# - 如何在客户端从 C# 调用 c++ .dll?
- node.js - 如何使用 Axios 包向 MailChimp api 发出 post 请求
- postgresql - aws rds postgres9.6:在数据库恢复地理位置列后返回字符串而不是对象
- javascript - 以 JS 为前端的 WebApi 2,如何保护未授权用户的页面?
- python - 从 Csv 文件中获取数组以绘制图表