Angular builder for generating sitemap from prerendered routes.
npm install nxt-sitemapsh
ng add nxt-sitemap
`
$3
`json
{
"build": {
...
},
"sitemap": {
"builder": "nxt-sitemap:sitemap",
"options": {
"srcDirectory": "./dist/demo/browser",
"baseUrl": "https://liquid-js.github.io/nxt-components/demo"
}
}
}
`
$3
`sh
ng run project:sitemap
`
$3
As described in #16051, Angular router, by default, removes trailing slashes from urls; however, when serving prerendered pages most web servers add trailing slash which causes unneccessary redirects and degraded SEO performance. To avoid this, consider including the following code in your app configuration (based on #16051 (comment)):
`ts
import { DefaultUrlSerializer, UrlSerializer, UrlTree } from '@angular/router'
export class TrailingSlashUrlSerializer extends DefaultUrlSerializer {
override serialize(tree: UrlTree): string {
return this._withTrailingSlash(super.serialize(tree))
}
private _withTrailingSlash(url: string): string {
const splitOn = url.indexOf('?') > -1 ? '?' : '#'
const pathArr = url.split(splitOn)
if (!pathArr[0].endsWith('/')) {
const fileName: string = url.substring(url.lastIndexOf('/') + 1)
if (fileName.indexOf('.') === -1) {
pathArr[0] += '/'
}
}
return pathArr.join(splitOn)
}
}
export const appConfig: ApplicationConfig = {
providers: [
...
{
provide: UrlSerializer,
useClass: TrailingSlashUrlSerializer
},
...
]
}
``