Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

All notable changes to this project will be documented in this file.

## 2026-11-21 - version 1.4.6

- **Every tag has its own page**: `/thoughts/tag/<tag>`, prerendered with its own title and canonical URL, and every tag pill in the list and the reader links to it. `/thoughts/tag/angular-guide` is now the reading list for this series. It's a path param rather than `?tag=` on purpose: prerendering writes one file per path, so a query-param page would be served the unfiltered list and then change under the reader during hydration. Prerendered routes went from 27 to 74
- **Cards are links now.** The Thoughts list cards were `div role="button"`s calling `router.navigate()`, so they had no `href` for crawlers, no middle-click, and nowhere to put the tag links (a link can't sit inside a button). The title is a real `routerLink`, and a stretched `::after` keeps the whole card clickable
- **fix: a mistyped URL failed the first navigation** with `NG04002: Cannot match any routes`. There's now a `**` route, last in the table, that redirects to the desktop
- The reader takes `:slug` as an input through `withComponentInputBinding()` instead of `toSignal(route.paramMap)`, which drops its `ActivatedRoute` and RxJS imports. A new spec runs the real route table with the real `appConfig`, so a missing route, a wildcard in the wrong place, or a router feature that's switched off fails a test
- **Angular guide, lesson 07: routing** (`/thoughts/angular-07-routing`). The playground parses a URL with Angular's own `UrlSerializer` and matches it against this site's actual route table. A checkbox moves the wildcard to the front, to show first-match-wins. Lesson 04's text now notes that lesson 07 replaced the code it shows
- Initial bundle 389.82 kB → 391.72 kB for the input-binding router feature, the two new routes and the lesson metadata. I didn't split that 1.9 kB any further

## 2026-11-21 - version 1.4.5

- **GET requests retry transient failures.** One network blip used to put the Projects app straight into "Failed to load projects". A functional interceptor, `retryTransientErrors`, now retries any GET that fails with a network error (status 0) or a 5xx, twice, 400ms and then 800ms later. A 404 fails straight away, and nothing but GETs is ever retried, because a retried POST is a second submission
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-paul",
"version": "1.4.5",
"version": "1.4.6",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
8 changes: 6 additions & 2 deletions src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
provideZonelessChangeDetection,
} from '@angular/core';
import { provideHttpClient, withFetch, withInterceptors } from '@angular/common/http';
import { provideRouter } from '@angular/router';
import { provideRouter, withComponentInputBinding } from '@angular/router';

import { routes } from './app.routes';
import { retryTransientErrors } from './shared/retry-transient-errors.interceptor';
Expand All @@ -37,7 +37,11 @@ export const appConfig: ApplicationConfig = {
// order on the way back. withInterceptors() takes plain functions; the
// class-based HTTP_INTERCEPTORS multi-provider is the legacy form.
provideHttpClient(withFetch(), withInterceptors([retryTransientErrors])),
provideRouter(routes),
// [ng-07 routing] withComponentInputBinding(): route params, query params
// and route data arrive as component inputs, so a routed component can
// declare `slug = input.required<string>()` instead of injecting
// ActivatedRoute and bridging an Observable.
provideRouter(routes, withComponentInputBinding()),
// SSR hydration: reuse server-rendered DOM instead of re-creating it.
// Lesson 12.
provideClientHydration(withEventReplay(), withIncrementalHydration()),
Expand Down
12 changes: 12 additions & 0 deletions src/app/app.routes.server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ describe('serverRoutes', () => {
expect(slugs).toEqual(expected);
});

it('prerenders a page for every tag', async () => {
const route = serverRoutes.find((r) => r.path === 'thoughts/tag/:tag');
expect(route?.renderMode).toBe(RenderMode.Prerender);

const params = await (
route as unknown as { getPrerenderParams: () => Promise<{ tag: string }[]> }
).getPrerenderParams();
const expected = [...new Set(THOUGHTS.flatMap((t) => t.tags))].sort();

expect(params.map((p) => p.tag).sort()).toEqual(expected);
});

it('keeps the catch-all route client-rendered', () => {
const route = serverRoutes.find((r) => r.path === '**');
expect(route?.renderMode).toBe(RenderMode.Client);
Expand Down
6 changes: 6 additions & 0 deletions src/app/app.routes.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export const serverRoutes: ServerRoute[] = [
renderMode: RenderMode.Prerender,
getPrerenderParams: async () => THOUGHTS.map((thought) => ({ slug: thought.slug })),
},
{
path: 'thoughts/tag/:tag',
renderMode: RenderMode.Prerender,
getPrerenderParams: async () =>
[...new Set(THOUGHTS.flatMap((thought) => thought.tags))].map((tag) => ({ tag })),
},
// The interactive desktop shell is client-rendered — hybrid rendering by route.
{
path: '**',
Expand Down
45 changes: 45 additions & 0 deletions src/app/app.routes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { TestBed } from '@angular/core/testing';
import { Router } from '@angular/router';
import { RouterTestingHarness } from '@angular/router/testing';
import { appConfig } from './app.config';
import { ThoughtDetailComponent } from './thoughts-content/thought-detail';
import { ThoughtsListComponent } from './thoughts-content/thoughts-list';

/**
* The real route table with the real router features from appConfig, so
* these catch a route that's missing, in the wrong order, or relying on a
* router feature that isn't switched on.
*/
async function navigate(url: string) {
TestBed.configureTestingModule({ providers: appConfig.providers });
const harness = await RouterTestingHarness.create();
await harness.navigateByUrl(url);
await harness.fixture.whenStable();
return { harness, router: TestBed.inject(Router) };
}

describe('app routes', () => {
it('sends an unknown URL to the desktop instead of failing the navigation', async () => {
const { router } = await navigate('/no-such-page');
expect(router.url).toBe('/');
});

it('binds :slug straight to the reader input', async () => {
const { harness } = await navigate('/thoughts/angular-02-components');
const reader = harness.routeDebugElement?.componentInstance;

expect(reader).toBeInstanceOf(ThoughtDetailComponent);
expect(harness.routeNativeElement?.textContent).toContain('Angular 02: Components');
});

it('serves a tag page that lists only that tag', async () => {
const { harness } = await navigate('/thoughts/tag/angular-guide');
const titles = [...harness.routeNativeElement!.querySelectorAll('.thought-card-title')].map(
(title) => title.textContent ?? '',
);

expect(harness.routeDebugElement?.componentInstance).toBeInstanceOf(ThoughtsListComponent);
expect(titles.length).toBeGreaterThan(0);
expect(titles.every((title) => title.includes('Angular 0'))).toBe(true);
});
});
12 changes: 12 additions & 0 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ export const routes: Routes = [
loadComponent: () =>
import('./thoughts-content/thoughts-list').then((m) => m.ThoughtsListComponent),
},
// [ng-07 routing] Same component as /thoughts; withComponentInputBinding()
// hands it :tag as its `tag` input. A path param rather than ?tag= so every
// tag page can be prerendered to its own static HTML file.
{
path: 'thoughts/tag/:tag',
loadComponent: () =>
import('./thoughts-content/thoughts-list').then((m) => m.ThoughtsListComponent),
},
{
path: 'thoughts/:slug',
loadComponent: () =>
import('./thoughts-content/thought-detail').then((m) => m.ThoughtDetailComponent),
},
// [ng-07 routing] The wildcard goes last: the router takes the first route
// that matches, in array order, and ** matches everything. Without it, a
// mistyped URL failed the initial navigation with NG04002.
{ path: '**', redirectTo: '' },
];
9 changes: 9 additions & 0 deletions src/app/shared/seo.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@ describe('SeoService', () => {
expect(title.getTitle()).toContain(SITE_NAME);
expect(doc.querySelector('script[type="application/ld+json"]')).toBeNull();
});

it('gives a tag page its own title and canonical URL', () => {
service.setListMeta('signals');

expect(title.getTitle()).toContain('signals');
expect(doc.querySelector('link[rel="canonical"]')?.getAttribute('href')).toMatch(
/\/thoughts\/tag\/signals$/,
);
});
});
});
7 changes: 4 additions & 3 deletions src/app/shared/seo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ export class SeoService {
});
}

setListMeta(): void {
const url = `${SITE_ORIGIN}/thoughts`;
const pageTitle = `Thoughts — ${SITE_NAME}`;
/** The Thoughts list, or one tag's page of it. Each tag page is its own canonical URL. */
setListMeta(tag?: string): void {
const url = tag ? `${SITE_ORIGIN}/thoughts/tag/${tag}` : `${SITE_ORIGIN}/thoughts`;
const pageTitle = tag ? `Thoughts tagged ${tag} — ${SITE_NAME}` : `Thoughts — ${SITE_NAME}`;

this.title.setTitle(pageTitle);
this.setName('description', LIST_DESCRIPTION);
Expand Down
7 changes: 4 additions & 3 deletions src/app/thoughts-content/lessons/lesson-04-signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ const SHIPPING: Record<Country, string[]> = {

<p>
<strong>Interop.</strong> <code>toSignal()</code> turns an Observable into a signal and
<code>toObservable()</code> goes the other way. The thought reader you're in uses it. It
<code>toObservable()</code> goes the other way. The thought reader you're in used it. It
used to read <code>route.snapshot</code> once, and since the router reuses the component
when only <code>:slug</code> changes, the series links (Part N of M, below) would have
shown the old lesson. Now the slug is a signal and everything derives from it.
shown the old lesson. Now the slug is a signal and everything derives from it. (Lesson 07
goes one step further: the router hands the slug over as an input.)
</p>
<app-code-block label="src/app/thoughts-content/thought-detail.ts" [code]="snippets.reader" />
<app-code-block label="thought-detail.ts, as of this lesson" [code]="snippets.reader" />

<h2>Expert</h2>
<p>
Expand Down
59 changes: 59 additions & 0 deletions src/app/thoughts-content/lessons/lesson-07-routing.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import * as axeMatchers from 'vitest-axe/matchers';
import { axe } from '../../../test/a11y';
import { LESSON_PAGES } from './lessons';
import { Lesson07Routing } from './lesson-07-routing';

expect.extend(axeMatchers);

describe('Lesson07Routing', () => {
let fixture: ComponentFixture<Lesson07Routing>;
let el: HTMLElement;

const text = (selector: string) => el.querySelector(selector)?.textContent ?? '';
const enterUrl = async (url: string) => {
const input = el.querySelector<HTMLInputElement>('#route-url')!;
input.value = url;
input.dispatchEvent(new Event('input'));
await fixture.whenStable();
};

beforeEach(async () => {
await TestBed.configureTestingModule({ imports: [Lesson07Routing] }).compileComponents();
fixture = TestBed.createComponent(Lesson07Routing);
await fixture.whenStable();
el = fixture.nativeElement as HTMLElement;
});

it('is registered as the lesson page for its thought', () => {
expect(LESSON_PAGES['angular-07-routing']).toBeDefined();
});

it('teaches at three levels, then pitfalls and interview questions', () => {
const headings = [...el.querySelectorAll('h2')].map((h) => h.textContent?.trim());
expect(headings).toEqual(
expect.arrayContaining(['Simple', 'Intermediate', 'Expert', 'Pitfalls', 'Interview questions']),
);
});

it("matches a URL against this site's real route table and splits it the way the router does", async () => {
await enterUrl('/thoughts/tag/rxjs?ref=dock#top');

expect(text('#route-matched')).toContain('thoughts/tag/:tag');
expect(text('#route-params')).toContain('tag = rxjs');
expect(text('#route-query')).toContain('ref = dock');
expect(text('#route-fragment')).toContain('top');
});

it('shows first-match-wins when the wildcard is moved to the front', async () => {
await enterUrl('/thoughts');
el.querySelector<HTMLInputElement>('#wildcard-first')!.click();
await fixture.whenStable();

expect(text('#route-matched')).toContain('**');
});

it('has no axe violations', async () => {
expect(await axe(el)).toHaveNoViolations();
});
});
Loading
Loading