check if a route exist in angular 2
问题 I want to check if a route exists in an angular project. For example user types http://localhost:4200/#/timestamp in the url bar and timestamp does not exist in the project, how will you be able to check without redirecting? 回答1: There is no way to check if the route path exists in the config, however you can do a redirect in configuration using ** in router config module. export const AppRoutes = [ { path: "", redirectTo: "home", pathMatch: "full" }, { path: '**', redirectTo: 'home'} ]; Or