#Next and Prev post navigation.

13 messages · Page 1 of 1 (latest)

celest flint
#

Ok, really struggling here on what I thought would be a piece of cake. I'm unable to get navigation to work between markdown files in the pages directory.

I used the prevUrl nextUrl props but they do not return a value.

Should I just make an array from the list of objects and index through them? Seems Astro's routing should solve that.

Read through the docs and came out confused.
I'm sure I'm just missing something obvious here.

Here's a link to the github repo file https://github.com/ResearchScientist/Website-Web-Dev-Notes/blob/master/src/components/NotesNavigation.astro .

Appreciate any help.

GitHub

A collection of my front end web development mark down notes turned to a webpage. - ResearchScientist/Website-Web-Dev-Notes

fallen ingot
#

you should have a src/pages/notes/[note].astro file like you'd have for a dynamic route, and in there you'd have a getStaticPaths function with a parameter of paginate - here is an example of what i'm using for my blog

GitHub

My personal website/portfolio. Contribute to jhilker98/jhilker98.github.io development by creating an account on GitHub.

celest flint
#

This is what I had on my [page].astro file

#
---
import NotesNavigation from "../../components/NotesNavigation.astro";

export async function getStaticPaths({ paginate }) {
    const allNotesPages = await Astro.glob('../notes/**/*.md');
    return paginate(allNotesPages, { pageSize: 1 });
}

const { page } = Astro.props;
---

<h1> page {page.currentPage} </h1>

<NotesNavigation prevUrl={page.url.prev} nextUrl={page.url.next}/>
#

I'm thinking of giving up on astro pagination and just write a function to make an array of objects and index through them.

fallen ingot
#

well I'm using content collections rather than Astro.glob - i'll try to take a look at it. maybe try using a [...page].astro file instead of just [page].astro?

celest flint
#

yup, tried with the ... but no change

fallen ingot
#

alright, I'll take a look at it and send a pull request

celest flint
#

Appreciate it, thanks.

fallen ingot
#

yep

fallen ingot
#

I think I figured out your problem - it's because you have static routes to all your markdown files instead of a dynamic route which could map over your pages, and those static routes have priority over dynamic routes (as seen here) - I'll go ahead and fix that tomorrow (and set up a content collection for you if you'd like, cause i have D&D tonight)

Astro Documentation

An intro to routing with Astro.

celest flint
#

That's splendid. In hindsight I should have read up more on routing and pagination before attempting this project. That's the fun way of learning I guess.

#

Enjoy your game session and thanks.