首页 > 解决方案 > 具有有限选项的角度路线作为参数

问题描述

我试图了解如何限制 Angular 路由中参数的选项。

当我声明一条路线时:

{
  path: 'food/:name',
  component: FoodComponent,
},

:name可以是任何东西。我想做的是将选项限制为:appleorange等。如果该值不是可用选项 - 将其作为 404 路由 ( path: '**') 捕获。

我想我总是可以在组件级别验证参数,如果值不匹配,则重定向到 404.. 但我想也许有办法在路由级别做到这一点。

提前致谢!

标签: angularroutingroutes

解决方案


推荐阅读