Learn Angular SEO routing best practices. Create clean URLs, handle 404 pages, set up redirects, optimize lazy loading, and generate sitemaps for better search rankings.
๐น Why Routing Matters for SEO in Angular
Angular apps use the Angular Router to manage navigation. While this makes SPAs fast and dynamic, it can create SEO challenges if not configured correctly:
- Ugly hash URLs (
/#/home
) are not SEO-friendly. - Improper redirects cause duplicate content.
- Missing 404 pages lead to indexing errors.
- Lazy loading, if not handled properly, may delay content loading for crawlers.
๐ To rank higher, you must configure routing in a crawler-friendly way.

๐น Step 1: Use SEO-Friendly URLs (No Hashbangs)
By default, Angular can use HashLocationStrategy, which creates URLs like:
https://example.com/#/about
These are bad for SEO. Instead, use PathLocationStrategy (clean URLs).
โ How to Enable Clean URLs
In app-routing.module.ts
:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{ path: '', loadComponent: () => import('./home/home.component').then(m => m.HomeComponent) },
{ path: 'about', loadComponent: () => import('./about/about.component').then(m => m.AboutComponent) },
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: false })], // ensure useHash is false
exports: [RouterModule]
})
export class AppRoutingModule {}
๐ Benefits:
- Cleaner, keyword-rich URLs
- Better for indexing & sharing
๐น Step 2: Handle 404 Pages Properly
Search engines expect a real 404 error code when a page doesnโt exist.
โ Create a 404 Page
In app-routing.module.ts
:
{ path: '**', loadComponent: () => import('./not-found/not-found.component').then(m => m.NotFoundComponent) }
๐ Best Practices:
- Show a helpful โPage Not Foundโ message.
- Return HTTP status 404 (when using Angular Universal or Express backend).
- Suggest links back to important pages.
๐น Step 3: Setup Redirects to Avoid Duplicate Content
Sometimes multiple routes point to the same content:
/home
vs/
/about-us
vs/about
This creates duplicate pages, confusing Google.
โ Example Redirect in Angular
{ path: 'home', redirectTo: '', pathMatch: 'full' }
๐ Tips:
- Always redirect old URLs to the latest version.
- Use 301 redirects (permanent) for SEO.
๐น Step 4: Lazy Loading & SEO Impact
Lazy loading routes improves performance but can delay content for crawlers.
โ Example of Lazy Loading
const routes: Routes = [
{ path: 'blog', loadChildren: () => import('./blog/blog.module').then(m => m.BlogModule) }
];
๐ Best Practices:
- Use preloading strategies for important pages.
- Example:
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
- Ensure critical content isnโt hidden behind too much lazy loading.
๐น Step 5: Prevent Duplicate URLs with Parameters
Example:
https://example.com/products?id=123
https://example.com/products/123
Both lead to the same content but look different.
๐ Solution:
- Use path parameters instead of query strings.
{ path: 'products/:id', loadComponent: () => import('./product/product.component').then(m => m.ProductComponent) }
- Add canonical URLs (as explained in Blog 2).
๐น Step 6: Generate an SEO-Friendly Sitemap
Once routing is set up, generate a sitemap to help crawlers discover all routes.
Tools:
npm install sitemap
- Angular Universal sitemap generator
๐ Always include dynamic routes (like /blog/:slug
).
๐น Final Thoughts
In this blog, we covered routing essentials for Angular SEO:
- Enabling clean, keyword-friendly URLs
- Handling 404s with proper error codes
- Redirects to avoid duplicate content
- Lazy loading best practices for SEO
- Using path parameters over query strings
- Generating SEO-friendly sitemaps
๐ Routing is the backbone of SEO in Angular.
In the next blog, weโll dive into Angular Universal (SSR) for SEO, where weโll set up server-side rendering to make Angular fully crawlable.
Share this:
- Click to share on Facebook (Opens in new window) Facebook
- Click to share on X (Opens in new window) X
- Click to share on WhatsApp (Opens in new window) WhatsApp
- Click to email a link to a friend (Opens in new window) Email
- Click to share on Pinterest (Opens in new window) Pinterest
- Click to share on LinkedIn (Opens in new window) LinkedIn
- Click to share on Threads (Opens in new window) Threads
- Click to share on Telegram (Opens in new window) Telegram