Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advance routing for ArchivePage as Child of a Page #699

Closed
gyretech opened this issue Jul 12, 2019 · 11 comments
Closed

Advance routing for ArchivePage as Child of a Page #699

gyretech opened this issue Jul 12, 2019 · 11 comments
Assignees
Milestone

Comments

@gyretech
Copy link
Contributor

So I have a page

[PageType(Title = "Slug page", UseBlocks = false)]
[PageTypeRoute(Title = "Default", Route = "/slugpage")]
public class SlugPage : Page<SlugPage>
{        
  ......
}

So I created a page /page-slug

Now I want a page /page-slug/slug-archive So I created the following

[PageType(Title = "Slug archive page", UseBlocks = false)]
[PageTypeRoute(Title = "Default", Route = "/slugarchive")]
public class SlugArchivePage : ArchivePage<SlugArchivePage >
{
  ....
}

But what I get is: Page "/page-slug/slug-archive" cannot be found. With the following output.

info: Piranha.AspNetCore.PageMiddleware[0]
      Found page
  Route: /slugpage/slug-archive

It is obviously looking for the archive page under the page route. How do I resolve this.

@tidyui
Copy link
Member

tidyui commented Jul 12, 2019

Have you created the page slug-archive below slug-page in the sitemap?

Regards

@gyretech
Copy link
Contributor Author

gyretech commented Jul 12, 2019 via email

@tidyui
Copy link
Member

tidyui commented Jul 12, 2019

Ok. I can see from the info printout that it doesn’t find your archive page, it finds “slug-page” and thinks “slug-archive” is an extra route param which it passes along. As your action doesn’t accept it MVC throws 404. Have you double checked the slug of the archive so it contains the “slug-page/“ prefix?

@gyretech
Copy link
Contributor Author

gyretech commented Jul 12, 2019 via email

@gyretech
Copy link
Contributor Author

gyretech commented Jul 12, 2019 via email

@gyretech
Copy link
Contributor Author

gyretech commented Jul 12, 2019 via email

@gyretech
Copy link
Contributor Author

gyretech commented Jul 12, 2019 via email

@tidyui
Copy link
Member

tidyui commented Jul 12, 2019

Hi again @gyretech!

I can see from the code that the standard setup will produce the exact error you're getting. The reason for this is that the PageRouter intercepts the parent page before the ArchiveRouter gets the chance to identify the child archive. The provided middleware (in the default order) just isn't capable of finding an archive page located below a regular page. To fix this in your project. let's take a look at what the extension method AddPiranha does:

public static IApplicationBuilder UsePiranha(this IApplicationBuilder builder)
{
    return builder
        .UseMiddleware<Piranha.AspNetCore.ApplicationMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.AliasMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.PageMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.PostMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.ArchiveMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.StartPageMiddleware>()
        .UseMiddleware<Piranha.AspNetCore.SitemapMiddleware>();
}

The problem here is that the ArchiveMiddleware is positioned after the PageMiddleware in the pipeline. Instead of calling this method, call the appropriate extension methods for adding all of the desired middleware in the order your need, in your case ArchiveMiddleware before PageMiddleware. To clarify, this will disable the possibility to add a regular page below an archive page.

Best regards

Håkan

@tidyui tidyui added this to the Version 7.0 milestone Jul 13, 2019
@tidyui
Copy link
Member

tidyui commented Jul 29, 2019

Btw @gyretech did you have a PR for this, because you solved it on your end right?

@gyretech
Copy link
Contributor Author

gyretech commented Jul 29, 2019 via email

@tidyui
Copy link
Member

tidyui commented Nov 10, 2019

Moved to 8.0 as we will implement a completely new routing middleware for this major version

@tidyui tidyui self-assigned this Nov 19, 2019
@tidyui tidyui closed this as completed in 887682f Dec 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants