Skip to content

Commit 88a1475

Browse files
committed
Page navigation on main site
1 parent f5e57b3 commit 88a1475

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/"
2+
@page "/{page:int}"
23
@using Markdig
34
@using X.PagedList
45
@using LinkDotNet.Blog.Web.Shared.Services
@@ -27,21 +28,25 @@
2728
<ShortBlogPost BlogPost="context" UseAlternativeStyle="@(currentLine++ % 2 != 0)"></ShortBlogPost>
2829
</Virtualize>
2930
</div>
30-
<BlogPostNavigation CurrentPage="@currentPage" OnPageChanged="@GetPage"></BlogPostNavigation>
31+
<BlogPostNavigation CurrentPage="@currentPage" OnPageChanged="@SetPageNumber"></BlogPostNavigation>
3132
</section>
3233

3334
@code {
35+
[Parameter]
36+
public int? Page { get; set; }
37+
3438
private IPagedList<BlogPost> currentPage = new PagedList<BlogPost>(null, 1, 1);
3539
private int currentLine;
3640

3741
private string ImageUrl => appConfiguration.Introduction.BackgroundUrl.ToAbsoluteUrl(navigationManager.BaseUri);
3842

39-
protected override async Task OnInitializedAsync()
43+
protected override async Task OnParametersSetAsync()
4044
{
41-
currentPage = await blogPostRepository.GetAllAsync(
45+
currentPage = await blogPostRepository.GetAllAsync(
4246
p => p.IsPublished,
4347
b => b.UpdatedDate,
44-
pageSize: appConfiguration.BlogPostsPerPage);
48+
pageSize: appConfiguration.BlogPostsPerPage,
49+
page: Page ?? 1);
4550
}
4651

4752
protected override async Task OnAfterRenderAsync(bool firstRender)
@@ -52,12 +57,8 @@
5257
}
5358
}
5459

55-
private async Task GetPage(int newPage)
60+
private void SetPageNumber(int newPage)
5661
{
57-
currentPage = await blogPostRepository.GetAllAsync(
58-
p => p.IsPublished,
59-
b => b.UpdatedDate,
60-
pageSize: appConfiguration.BlogPostsPerPage,
61-
page: newPage);
62+
navigationManager.NavigateTo($"/{newPage}");
6263
}
6364
}

0 commit comments

Comments
 (0)