angular 2 route to 404 page when route param is invalid

后端 未结 4 1843
闹比i
闹比i 2021-02-14 01:17

Say I have an route with a param like this (in Angular 2): /user1/products/:id, which could have child routes like /user1/products/3/reviews.

W

4条回答
  •  遥遥无期
    2021-02-14 01:51

    Update

    In the new Router V3 you can use guards as explained in https://angular.io/guide/router#canactivate-requiring-authentication

    Original

    I think you should use @CanActivate() to do the check. If you forward in @CanActivate() the invalid URL shouldn't be added to the history (not tried)

    See also https://github.com/angular/angular/issues/4112 for how to use DI in @CanActivate()

提交回复
热议问题