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

Unable to AddPageRoute to the default page #6338

Closed
hishamco opened this issue May 29, 2017 · 6 comments
Closed

Unable to AddPageRoute to the default page #6338

hishamco opened this issue May 29, 2017 · 6 comments

Comments

@hishamco
Copy link
Contributor

hishamco commented May 29, 2017

Razor Page by default looking for index.cshtml, using AddPageRoute i'm not able to route to home.cshtml using:

services.AddMvc()
     .AddRazorPagesOptions(options =>
     {
          options.RootDirectory = "/Pages";
          options.AddPageRoute("/Home.cshtml", "/");
     });

Perhaps someone may ask why we need to home pages?
1- Assume I don't have index.cshtml at all
2- Look at CH9 as example, whenever a live event streaming, a new home page shows up instead of the default one

@pranavkm any idea why this not work as expected?!!

@mikebrind
Copy link

It has only just been implemented and will be available in Preview 2.

#6325

@hishamco
Copy link
Contributor Author

hishamco commented May 30, 2017

@mikebrind I already saw that issue and blog about the Friendly URLs in Razor Pages 😄 , my issue with routing /

thanks

@pranavkm
Copy link
Contributor

@hishamco - you'll need the page name not the path as the first parameter. The pageName is the app relative file path without the extension. In this case, it'll be /Home. See https://github.com/aspnet/Mvc/blob/dev/test/WebSites/RazorPagesWebSite/Startup.cs#L22

@hishamco
Copy link
Contributor Author

hishamco commented Jun 1, 2017

@pranavkm yep it's my mistake, but even if I used the relative file path without the extension, it doesn't route to the /

@pranavkm pranavkm self-assigned this Jun 19, 2017
@pranavkm pranavkm added this to the 2.0.0 milestone Jun 19, 2017
pranavkm added a commit that referenced this issue Jun 19, 2017
pranavkm added a commit that referenced this issue Jun 19, 2017
pranavkm added a commit that referenced this issue Jun 20, 2017
* Allow AddPageRoute to route to pages root.
Fixes #6338
@pranavkm
Copy link
Contributor

@hishamco - this is fixed post 2.0.0-preview2. You'll have to use options.AddPageRoute("/Home", string.Empty); to route to the pages root.

@hishamco
Copy link
Contributor Author

Thanks a lot @pranavkm

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants