I Help You

Robots.txt for Angular (Example, Template & Best Practices)

QUICK SUMMARY

  • Place robots.txt in Angular's /src/ directory — Angular CLI copies it to /dist/ on build
  • Angular is a SPA — all routes render via index.html, so SSR improves crawl reliability
  • Block admin, API, and dashboard routes; never block application routes you want indexed
  • Use Angular Universal (Angular SSR) for content-critical pages
  • Generate a sitemap from your Angular routes and reference it in Sitemap:

A robots.txt for Angular must be placed in the /src/ directory — Angular CLI picks it up during ng build and copies it to your distribution folder. Like all single-page applications, Angular routes are handled client-side by Angular Router, which means robots.txt Disallow rules apply to the URL paths just as they would for server-rendered pages. For content that needs strong SEO, pairing robots.txt with Angular Universal gives the best results.

Angular robots.txt template

This template blocks admin, API, and protected routes while leaving your application routes open. Adjust paths to match your app's routing structure and use our robots.txt generator to customise it:

robots.txt
User-agent: *
Disallow: /admin/
Disallow: /api/
Disallow: /dashboard/

Sitemap: https://yourdomain.com/sitemap.xml

What each rule does

  • /admin/: Angular admin interfaces or dashboards. Even though these are client-side routes, blocking them in robots.txt tells Googlebot not to attempt crawling them.
  • /api/: If your Angular app communicates with a backend API on the same domain, block these paths. They return structured data, not HTML pages, and have no indexable value.
  • /dashboard/: Authenticated user areas with no public content. Blocking these prevents them from appearing in search results even if they're discoverable via links.

After deploying, test this robots.txt using our robots.txt tester to confirm all public application routes are accessible. For more configuration examples, browse the robots.txt examples library.

Common Angular robots.txt mistakes

These errors are specific to Angular's build and routing architecture.

Placing robots.txt in /dist/ instead of /src/

The /dist/ directory is regenerated every time you run ng build. Files placed there directly are overwritten. Always place robots.txt in /src/ so it's included in the Angular CLI build process.

Blocking Angular application routes you want indexed

Angular client-side routes (/about, /products, /blog) should not be blocked in robots.txt if you want them to appear in search results. Only block routes that genuinely have no SEO value (admin areas, dashboards, API paths).

Not using Angular Universal for content-heavy apps

robots.txt can't fix client-side rendering limitations. If your Angular app serves content that needs to rank in search, SSR is essential — not optional.

Missing the Sitemap directive

Angular Router doesn't auto-generate a sitemap. You need to create one as part of your build process and reference it in your robots.txt Sitemap: line.

Angular robots.txt best practices

Follow these steps for a reliable robots.txt setup in Angular projects.

Place robots.txt in /src/, never in /dist/

Angular CLI includes /src/ files in the build output. Placing robots.txt in /dist/ means it's deleted every time ng build runs.

Use Angular SSR for content that must rank

For landing pages, product pages, blog posts, or any content with SEO value, Angular Universal (ng add @angular/ssr) provides server-rendered HTML that Googlebot can index reliably without JavaScript execution.

Generate a route-based sitemap at build time

Extract your Angular route configuration and generate a sitemap.xml during the build process. Reference it in robots.txt so Google can discover all your application routes.

Test after every ng build deployment

Use our free robots.txt tester to confirm your public routes are accessible and your admin/API paths are correctly blocked after each deployment.

When NOT to use these rules

Applying these directives incorrectly can hide Angular routes you want indexed or break rendering. Keep these limits in mind:

  • Do NOT block Angular client-side application routes you want indexed — Angular Router routes are URL paths that Googlebot respects in robots.txt.
  • Do NOT block your JavaScript bundles produced by ng build — Googlebot may need them to render your pages if you don't have Angular SSR enabled.
  • Do NOT use Disallow: / to hide a non-production Angular build — use proper environment-specific deployment workflows or HTTP authentication instead.

Configure robots.txt for your Angular project

Test your existing configuration or generate a new file tailored to Angular — free, no account required.

Related robots.txt guides

More platform-specific guides in the series.

Frequently Asked Questions

Common questions about robots.txt in Angular applications.

Where do I put robots.txt in an Angular project?

Place robots.txt in Angular's /src/ directory. When you run ng build, Angular CLI copies all files from /src/ that aren't TypeScript, component, or template files to the /dist/ output directory. Files placed in /src/ are included in the build output and will be served at yoursite.com/robots.txt. Do not place robots.txt in /dist/ directly — this directory is regenerated on every build.

Does Angular have SEO limitations like other SPAs?

Yes — by default, Angular is a client-side SPA that renders all routes via Angular Router from a single index.html. Googlebot must execute JavaScript to see your content. For content pages that need to rank in search, Angular Universal (now called Angular SSR in Angular 17+) adds server-side rendering. Without SSR, your content is crawlable but indexing quality depends on how well Googlebot executes your JavaScript.

How do I add Angular Universal for better SEO?

In Angular CLI projects, run: ng add @angular/ssr. This adds server-side rendering support, transforming your Angular SPA into a server-rendered application. With SSR enabled, Googlebot receives pre-rendered HTML directly — vastly improving crawl reliability. You should then implement robots.txt alongside SSR for the best SEO outcomes.

Can I use robots.txt to block Angular client-side routes?

Yes, and it works as expected. Even though Angular routes are handled client-side by Angular Router, Googlebot treats them as real URL paths and respects robots.txt Disallow rules for those paths. Googlebot won't crawl a URL that matches a Disallow rule, regardless of whether it's a server file or a client-side route.

How do I generate a sitemap for an Angular app?

Angular CLI doesn't generate sitemaps automatically. Options include: (1) a custom script in your build pipeline that generates sitemap.xml from your route config; (2) tools like angular-sitemap; or (3) if using Angular Universal/SSR, a server-side endpoint that generates the sitemap dynamically. Reference the output URL in your robots.txt Sitemap: directive.

For more configuration examples, see our robots.txt examples and best practices guide.