liveBook · Manning

Relative URL

As explained in Pro ASP.NET Core 7, Tenth Edition

A relative URL identifies a resource or endpoint by a path resolved against a base URL rather than by a complete absolute address.

A relative URL names a navigation target without a leading slash, so Blazor WebAssembly resolves it against the application root defined by the base element. section 37.3.2

In a Blazor WebAssembly component, the leading character changes the destination:

  • forms/create resolves against the /webassembly/ application root and navigates to /webassembly/forms/create. section 37.3.2
  • /forms/create resolves from the site root and navigates outside the URLs managed by the /webassembly/ application. section 37.3.2
  • Use this distinction for navigation URLs; URLs in the @page directive are unaffected. section 37.3.2

Component navigation

A NavLink can use href="forms/create" to keep navigation beneath the configured application root.

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Explains path resolution and leading-slash behavior, while limiting the rule to navigation URLs rather than @page routes.
Examples
Uses forms/create, /forms/create, NavLink href values, and the /webassembly/ application root.
What you can do after
Apply it via Blazor WebAssembly navigation to keep component links inside a deployed application subpath.
How it connects
Connects relative URLs with Blazor WebAssembly, navigation, base URLs, Razor components, and the @page directive.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.