我的角度应用程序中有以下路线:
{ path: '', redirectTo: '/exercise-log', pathMatch: 'full'},
{ path: 'exercise-log/:date', component: ExerciseListComponent },
{ path: 'exercise-log', component: ExerciseListComponent }
我想删除exercise-log
并将''
重定向到'exercise-log/:date'
,然后改用今天的日期。
我该怎么做?我曾考虑过要在route模块的构造函数中设置一个date变量,但这感觉很不对。更新:尝试在构造函数中设置它似乎不是现在尝试的方法。
您可以在不带参数的情况下向路由添加CanActivate
路由保护,并且在重新路由至canActivate
路由时始终在exercise-log/currentDate
方法中返回false。
然而,这似乎有点不可靠,所以可能有更好的方法来实现这一目标。
您只需将其与当前时间重定向到exercise-log/:date
{path:'exercise-log',redirectTo:'/ exercise-log /'+ Date.now(),pathMatch:'full'}