Page links
Inline mentions and link blocks that point at pages your app owns.
The pages add-on links to other pages in your app. Type [[ for an inline mention, or use the slash menu's Page item for a link block. Your app owns the page tree, the search, and the routing; the editor stores the page id with a cached title and icon. Full behaviour is in Blocks → Page links.
Install
npx shadcn@latest add https://blockcn.com/r/pages.jsonUse it
"use client";
import { Editor } from "@/components/editor/Editor";
import { useEditor } from "@/components/editor/useEditor";
import { createBlockcnEditor } from "@/components/editor/preset";
import { pages } from "@/components/editor/pages/pagesAddon";
const kit = createBlockcnEditor({
addons: [
pages({
fetchPages: async (query) => {
const response = await fetch(`/api/pages?q=${encodeURIComponent(query)}`);
return response.json();
},
onNavigate: (pageId) => window.location.assign(`/pages/${pageId}`),
}),
],
});
export function BlockEditor() {
const editor = useEditor({ extensions: kit.extensions });
return (
<Editor editor={editor}>
<Editor.Frame>
<Editor.Content />
<Editor.Chrome>
<Editor.SideMenu />
<Editor.FormattingToolbar />
{kit.chrome}
</Editor.Chrome>
</Editor.Frame>
</Editor>
);
}Each page is { id, title, icon? }. Without createBlockcnEditor, spread createPageExtensions({ fetchPages }) from @/components/editor/pages/pages and add PAGE_SLASH_CATEGORY to the slash categories.
Options
| Option | Required | |
|---|---|---|
fetchPages(query) | yes | Your page search. Also refreshes cached titles once after the editor loads. |
fetchPagesById(ids) | no | Tried first on refresh, so a renamed page is found by id. If it fails, the title search runs instead. |
createPage(title) | no | Offers Create when no page has that exact title. |
onNavigate(pageId) | no | Runs when someone opens a page. |
slash | no | false leaves the slash menu unchanged; [[ still works. |
A page the search does not return is marked missing and keeps its last title. A failed search leaves the cache alone.