Skip to content

Fix short URLs when a PageRouteTransformerConvention is used - #1903

Open
mt0321 wants to merge 1 commit into
YAFNET:masterfrom
mt0321:short-route-transformer
Open

mt0321 wants to merge 1 commit into
YAFNET:masterfrom
mt0321:short-route-transformer

Conversation

@mt0321

@mt0321 mt0321 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

ShortRouteConvention sets the short URL segment (e.g. topic for Posts) on each selector's route template. When the host also adds a PageRouteTransformerConvention (for example, kebab-case URLs), ASP.NET Core rebuilds every page route from the selector's PageRouteMetadata and ignores the edited template. So the short URLs never take effect:

  • The pages keep their old routes (e.g. /forums/posts/1/name).
  • LegacyUrlRedirectRule redirects those URLs to the short URL (/forums/topic/1/name).
  • The short URL has no route and returns 404.

Change

ShortRouteConvention now also replaces the page name in the selector's PageRouteMetadata. Note that PageRoute starts with a slash (/Forums/Posts).

Tests

  • New ShortUrlTests.Convention_PageRouteMetadata_Test (with and without the leading slash). It fails without the fix.
  • All YAFNET.Tests unit tests pass (2171).
  • Also checked in a host app that uses a PageRouteTransformerConvention (kebab-case): topic, forum and profile pages resolve at their short URLs, and old URLs redirect to them.

…-case urls) the pages kept their old routes (e.g. /forums/posts/1/name) and the redirect to the short url returned 404; the convention replaces the page name in the page route metadata too

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant