Navigation Configuration #
This guide explains how to configure the navigation for your Valaxy site using the valaxy-theme-antfu
theme.
导航配置 #
本指南将解释如何使用 valaxy-theme-antfu
主题配置 Valaxy 站点的导航。
Main Navigation #
The main navigation menu appears at the top of your site. You can configure it in your valaxy.config.ts
file:
主导航 #
主导航菜单出现在您网站的顶部。您可以在 valaxy.config.ts
文件中配置它:
import type { ThemeConfig } from 'valaxy-theme-antfu'
import { defineConfig } from 'valaxy'
export default defineConfig<ThemeConfig>({
theme: 'antfu',
themeConfig: {
nav: [
{
text: 'Home',
link: '/',
icon: 'i-ri-home-line'
},
{
text: 'Posts',
link: '/posts',
icon: 'i-ri-article-line'
},
{
text: 'Notes',
link: '/notes',
icon: 'i-ri-sticky-note-line'
},
{
text: 'Demos',
link: '/demos',
icon: 'i-ri-code-box-line'
},
{
text: 'Talks',
link: '/talks',
icon: 'i-ri-presentation-line'
},
{
text: 'Features',
link: '/features',
icon: 'i-ri-function-line'
}
],
// Other configuration options...
}
})
Navigation Item Properties #
Each navigation item can have the following properties:
导航项属性 #
每个导航项可以具有以下属性:
text
: The display text for the navigation itemlink
: The URL to navigate to when the item is clickedicon
: An optional icon to display next to the text (using Iconify format)title
: An optional title attribute for the linktarget
: An optional target attribute for the link (e.g.,_blank
to open in a new tab)rel
: An optional rel attribute for the linkitems
: An optional array of sub-items for dropdown menus
Using Icons #
The valaxy-theme-antfu
theme uses Iconify for icons. You can use any icon from the Iconify collection by prefixing it with i-
.
使用图标 #
valaxy-theme-antfu
主题使用 Iconify 作为图标。您可以通过在图标前加上 i-
前缀来使用 Iconify 集合中的任何图标。
Common icon sets include:
ri
: Remix Iconcarbon
: Carbon Iconsmdi
: Material Design Icons
For example:
i-ri-home-line
: Home icon from Remix Iconi-carbon-document
: Document icon from Carbon Iconsi-mdi-github
: GitHub icon from Material Design Icons
Dropdown Menus #
You can create dropdown menus by adding an items
array to a navigation item:
下拉菜单 #
您可以通过向导航项添加 items
数组来创建下拉菜单:
nav: [
// ... other items
{
text: 'Resources',
icon: 'i-ri-book-line',
items: [
{
text: 'Documentation',
link: '/docs'
},
{
text: 'API Reference',
link: '/api'
},
{
text: 'Examples',
link: '/examples'
}
]
}
]
Sub Navigation #
The sub-navigation menu appears below the main navigation on certain pages. You can configure it in your valaxy.config.ts
file:
子导航 #
子导航菜单出现在某些页面的主导航下方。您可以在 valaxy.config.ts
文件中配置它:
themeConfig: {
subNav: [
{
text: 'Posts',
link: '/posts'
},
{
text: 'Notes',
link: '/notes'
},
{
text: 'Demos',
link: '/demos'
},
{
text: 'Talks',
link: '/talks'
},
{
text: 'Features',
link: '/features'
}
]
}
Using the Sub Navigation Component #
To display the sub-navigation menu on a page, add the <AntfuSubNav />
component to your Markdown file:
使用子导航组件 #
要在页面上显示子导航菜单,请将 <AntfuSubNav />
组件添加到您的 Markdown 文件中:
---
title: My Page
---
<AntfuSubNav />
# My Page Content
Content goes here...
Navigation Controls #
You can configure additional controls in the navigation bar, such as the locale toggle and theme toggle:
导航控件 #
您可以在导航栏中配置其他控件,例如语言切换和主题切换:
themeConfig: {
navControls: {
localeToggle: true, // Whether to enable the locale toggle
themeToggle: true // Whether to enable the theme toggle (light/dark mode)
}
}
Mobile Navigation #
The valaxy-theme-antfu
theme automatically adapts the navigation menu for mobile devices. On smaller screens, the navigation menu collapses into a hamburger menu.
移动导航 #
valaxy-theme-antfu
主题自动适应移动设备的导航菜单。在较小的屏幕上,导航菜单会折叠成汉堡菜单。
Social Links #
You can add social links to your navigation by including them in the nav
array:
社交链接 #
您可以通过将社交链接包含在 nav
数组中来将其添加到导航中:
nav: [
// ... other items
{
text: 'GitHub',
link: 'https://github.com/username/repo',
icon: 'i-ri-github-fill',
target: '_blank'
},
{
text: 'Twitter',
link: 'https://twitter.com/username',
icon: 'i-ri-twitter-fill',
target: '_blank'
}
]
Complete Example #
Here’s a complete example of navigation configuration:
完整示例 #
以下是导航配置的完整示例:
import type { ThemeConfig } from 'valaxy-theme-antfu'
import { defineConfig } from 'valaxy'
export default defineConfig<ThemeConfig>({
theme: 'antfu',
themeConfig: {
nav: [
{
text: 'Home',
link: '/',
icon: 'i-ri-home-line'
},
{
text: 'Posts',
link: '/posts',
icon: 'i-ri-article-line'
},
{
text: 'Notes',
link: '/notes',
icon: 'i-ri-sticky-note-line'
},
{
text: 'Demos',
link: '/demos',
icon: 'i-ri-code-box-line'
},
{
text: 'Talks',
link: '/talks',
icon: 'i-ri-presentation-line'
},
{
text: 'Features',
link: '/features',
icon: 'i-ri-function-line'
},
{
text: 'Resources',
icon: 'i-ri-book-line',
items: [
{
text: 'Documentation',
link: '/docs'
},
{
text: 'API Reference',
link: '/api'
},
{
text: 'Examples',
link: '/examples'
}
]
},
{
text: 'GitHub',
link: 'https://github.com/username/repo',
icon: 'i-ri-github-fill',
target: '_blank'
}
],
subNav: [
{
text: 'Posts',
link: '/posts'
},
{
text: 'Notes',
link: '/notes'
},
{
text: 'Demos',
link: '/demos'
},
{
text: 'Talks',
link: '/talks'
},
{
text: 'Features',
link: '/features'
}
],
navControls: {
localeToggle: true,
themeToggle: true
}
}
})
Conclusion #
By configuring the navigation for your Valaxy site, you can create a user-friendly interface that makes it easy for visitors to find and explore your content.
结论 #
通过为您的 Valaxy 站点配置导航,您可以创建一个用户友好的界面,使访问者能够轻松找到和浏览您的内容。