Using Angular Router
In Everyday Market, let's implement the following routes
:
/products
: This is the default route that displays the product's listing homepage./products/newÂ
: This displays the form to create a new product./products/:idÂ
: This displays product details for the specified productid
. The fact that theÂid
is prefixed with a colon instructs Angular Router to treat it as a parameter and match it with the URL.
These routes
are illustrated in the following diagram:
Â
Using Angular Router, let's implement client-side routing with the following steps:
- Create the components to be used in the new
routes
with the following command:
ng generate component modules/market/product-view-page ng generate component modules/market/product-edit-page
- Define the market
routes
configuration inÂmarket.module.ts
 as follows:- Import
RouterModule
andRoutes
from theÂ@angular/router
package. - Create aÂ
routes
configuration object. - Import
RouterModule
as part ofMarketModule
. - You can remove the exportedÂ
ProductsPageComponent...
- Import