DEV Community

GaurangDhorda
GaurangDhorda

Posted on

1 1

Generate breadcrums for your Angular-Router and set page title dynamically.

In this example I am going to explain you that You can use library to generate breadcrumbs, and also set each page title dynamically.

first you need to install this library to your angular project.

npm install set-title-with-breadcrumbs

This will install library called set-title-with-breadcrumbs, this library is used to generate breadcrumbs component and also you can set page title using angular router. After installing this library..

Go to your app.module.ts file and add below code

import { SetTitleWithBreadcrumbsModule} from 'set-title-with-breadcrumbs';
    @NgModule({
        imports : [SetTitleWithBreadcrumbsModule]
    })
Enter fullscreen mode Exit fullscreen mode

in side your app-routing.module.ts file you have to add new data:{} object with breadcrumbs and title object property.

const routes: Routes = [
  {
    path: 'home',
    component: HomeComponent,
    data: { title: 'Home Page', breadcrums: 'Home' },
    children: [
      {
        path: 'records',
        component: RecordsComponent,
        data: { title: 'Find Records Page', breadcrums: 'Find-Records' },
        children: [
          {
            path: 'child',
            component: ChildComponent,
            data: { title: 'Child Record Page', breadcrums: 'Child-Record' }
          }
        ]
      }
    ]
  }
]
Enter fullscreen mode Exit fullscreen mode

as you can see above, each router-path has data object with two property - breadcrumbs and title.

Now inside your app.component.html file you need to add component of library.

<lib-set-title-with-breadcrumbs></lib-set-title-with-breadcrumbs>
<router-outlet></router-outlet>
Enter fullscreen mode Exit fullscreen mode

You can support me here.

Alt Text

Connect with me by email : grdtechlab@gmail.com

Working demo in this stackblitz link

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay