zl程序教程

您现在的位置是:首页 >  其它

当前栏目

[Angular2 Router] Redirects and Path Matching - Avoid Common Routing Pitfall

and path Router Common matching Angular2 routing avoid
2023-09-14 08:59:19 时间

In this tutorial we are going to learn how we can can configure redirects in the angular 2 router configuration. We are also going to see again another example on how the order of the configuration might trip us. We are going to see the different between path matching in prefix mode vs full mode, and we are going to learn why redirects should be in general configured using full path matching.

 

{path: 'legacy-url', redirectTo: '/home', pathMatch: 'full'},

pathMatch: 'full' : only match 'legacy-url', won't match 'legacy-url/1';

 

{path: 'legacy-url', redirectTo: '/home', pathMatch: 'prefix'},

pathMatch: 'prefix' : not only match 'legacy-url', but also match 'legacy-url/1';

 

Notice, this redirectTo should be define on the top of other routers.