CmsKit - Alternative way to handle pages

pull/7596/head
enisn 5 years ago
parent 42cf0238ba
commit a5bf8ebe9e

@ -61,10 +61,6 @@ namespace Volo.CmsKit.Public.Web
{
Configure<RazorPagesOptions>(options =>
{
if (GlobalFeatureManager.Instance.IsEnabled<PagesFeature>())
{
options.Conventions.AddPageRoute("/CmsKit/Pages/Index", @"{*pageUrl:minlength(1)}");
}
});
}
}

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.CmsKit.Public.Pages;
namespace Volo.CmsKit.Public.Web.Controllers
{
public class PageController : CmsKitPublicControllerBase
{
protected IPageAppService PageAppService { get; }
public PageController(IPageAppService pageAppService)
{
PageAppService = pageAppService;
}
[HttpGet("/{*url}", Order = int.MaxValue)]
public async Task<IActionResult> Index(string url)
{
var page = await PageAppService.FindByUrlAsync(url);
if (page == null)
{
return NotFound();
}
return View("~/Views/Page/Index.cshtml", page);
}
}
}

@ -1,13 +0,0 @@
@page "{*pageUrl}"
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.CmsKit.Localization
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Pages.IndexModel
@inject IHtmlLocalizer<CmsKitResource> L
@await Component.InvokeAsync(typeof(DefaultPageViewComponent),
new
{
pageId = Model.Page.Id,
title = Model.Page.Title
})

@ -1,34 +0,0 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.CmsKit.Public.Pages;
using Volo.CmsKit.Web.Pages;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Pages
{
public class IndexModel : CommonPageModel
{
[BindProperty(SupportsGet = true)]
public string PageUrl { get; set; }
protected readonly IPageAppService PageAppService;
public PageDto Page;
public IndexModel(IPageAppService pageAppService)
{
PageAppService = pageAppService;
}
public async Task<IActionResult> OnGetAsync()
{
Page = await PageAppService.FindByUrlAsync(PageUrl);
if (Page == null)
{
return NotFound();
}
return Page();
}
}
}

@ -0,0 +1,9 @@
@model Volo.CmsKit.Public.Pages.PageDto
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@await Component.InvokeAsync(typeof(DefaultPageViewComponent), new
{
pageId = Model.Id,
title = Model.Title
})
Loading…
Cancel
Save