Routing
One of the most important things while creating an Angular project is creating routes. Without routes you cannot render any page in the browser.
In this page we will learn how to create routes for our pages.
When creating angular project make sure that you select routing to setup router by default.
Defining routes
app.routes.ts file will be created automatically, here we can define our paths for each routes.
But when we are working on a large projects, such as Mofi, number of paths will grow very fast, so we create a separate file routes.ts in routes folder to keep our routes more organized.
Routes.ts
import { Routes } from '@angular/router';
export const content: Routes = [
{
path: 'dashboard',
data: {
title: "Dashboard",
breadcrumb: "Dashboard",
},
loadChildren: () => import('../../components/dashboard/dashboard.routes'),
},
{
path: 'widgets',
data: {
title: "Widgets",
breadcrumb: "Widgets",
},
loadChildren: () => import('../../components/widgets/widgets.routes'),
},
] as Routes;
We give the path for our module, and in loadChildren function we provide our module .
And then we will import this routes.ts file in our app.routes.ts file.
app.routes.ts
import { Routes } from '@angular/router';
import { Content } from './shared/components/layout/content/content';
import { content } from './shared/routes/routes';
export const routes: Routes = [
{
path: '',
component: Content,
children: content,
},
];