Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Routing for View Pages #5353

@pranavkm

Description

@pranavkm

Routing

By default, the route for each page is mapped at it's application relative path (with the cshtml extension). The file name Index is optional and has the same behavior as routing to an action named Index in conventional routing i.e.
/Home/Index and /Home are equivalent. The optional value of the@page directive can be used to append a suffix to this route. Consider,

Page Directive Routes
/About.cshtml @page http://myappdomain.net/About
/Contact.cshtml @page "location/{zip}" http://myappdomain.net/Contact/location/98052
/Catalog/Index.cshtml @page http://myappdomain.net/Catalog http://myappdomain.net/Catalog/Index
/Catalog/Books.cshtml @page "{id?}" http://myappdomain.net/Catalog/Books/ http://myappdomain.net/Catalog/Books/12

Friendly urls

Associated with each page is an application model type similar to ControllerModel. We'd build on top of this to provide simple runtime configuration of routes. For instance, to configure an additional route to the /Catalog/Books.cshtml, here's what the Startup code might look like:

services
    .AddMvc()
    .AddRazorPages(options =>
    {
        options.MapPageRoute("Books/{id?}", "/Catalog/Books.cshtml");
    });

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions