In angular cli how can you add meta data to routes e.g. title and description tags?
These are my routes:
import { Route} from '@angular/router';
import { HomeComponent } from './home.component';
export const HomeRoutes: Route[] = [
{
path: '',
component: HomeComponent
},
{
path: 'home',
component: HomeComponent
}
];
I want to add title and description to these routes so that they are seen in the browser e.g. title for each route.
Furthermore, I would like them to be picked up by bots e.g. google seo bots.
I’m using angular cli with webpack, angular version 4, and typescript.
Current Error:
2
Answers
There’s a npm module ng2-metadata [https://www.npmjs.com/package/ng2-metadata%5D
it will serve the need.
Sample Code.
Add this in app.module.ts
And inject it in component constructor.
As the author
ng2-metadata
and@ngx-meta/core
projects, I’d suggest you to have a look at the package description (README file), as README files contain up-to-date information in most cases.There’s a depreciation warning on the npm page of
ng2-metadata
, saying that the project is deprecated, no longer maintained and now continues at@ngx-meta/core
.If you switch using
@ngx-meta/core
, you’ll notice that the current issues you described here have already been resolved.About
@ngx-meta/core
:@ngx-meta/core
is the successor ofng2-metadata
, and the actual releases arev0.4.x
andv0.2.x
.The latest release for Angular 4 is
v0.4.0-rc.1
as of now.The latest release for Angular 2 is
v0.2.0-rc.5
as of now.