angular - 具有有限选项的角度路线作为参数
问题描述
我试图了解如何限制 Angular 路由中参数的选项。
当我声明一条路线时:
{
path: 'food/:name',
component: FoodComponent,
},
:name
可以是任何东西。我想做的是将选项限制为:apple
或orange
等。如果该值不是可用选项 - 将其作为 404 路由 ( path: '**'
) 捕获。
我想我总是可以在组件级别验证参数,如果值不匹配,则重定向到 404.. 但我想也许有办法在路由级别做到这一点。
提前致谢!
解决方案
推荐阅读
- webpack - LodashModuleReplacementPlugin
- python - 为什么多索引数据框会在选择后返回所有索引?
- reactjs - “元素”类型缺少“SVGSVGElement”类型的以下属性
- python - 尝试在 Django 模板中调整图像大小时,连接路径位于基本路径组件之外
- tensorflow - 无需编译即可为 Keras 模型运行 TFMA
- javascript - 如果任何基于父类的组件收到新的道具但没有设置状态......它会调用 componentDidMount()
- angular - 更新数据源后可扩展的 Mat-Table 自行关闭
- spring - 如何在 Spring 应用程序中使用嵌入式数据库 MariaDB 为 db 和表指定 utf8 编码?
- go - Instagram 媒体 ID 到时间戳的转换
- javascript - 为什么向下滚动时我的社交媒体面板出现故障?