Appearance
π§© Metadata in Vue Router Routes β
WBC-Routes2 allows injecting metadata directly in the meta field of a Vue Router route. This enhances SEO, social sharing, and accessibility by defining structured information at the route level.
π Why Inject Metadata via Routes? β
- Simplifies content-based routing and SEO setup
- Avoids manual
<head>management - Dynamically updates title, description, Open Graph, Twitter cards, etc.
- Useful for CMS-like applications or documentation engines
π οΈ Example: Metadata in Route Definition β
js
{
path: "/wbc/intro",
name: "WBCIntroPage",
component: WBC,
props: {
item: "./docs/introduction.md"
},
meta: {
comp: "meta",
title: "Introduction to WBC-Routes2",
description: "Discover WBC-Routes2 and how it redefines dynamic, multilingual routing in Vue.js apps.",
keywords: ["WBC-Routes2", "Vue", "Markdown", "meta", "dynamic routing"],
language: "en",
viewport: "width=device-width, initial-scale=1.0",
author: "Wissem Boughamoura",
twitter: "@WBoughamoura",
site: "http://wi-bg.com",
"og:title": "Intro to WBC-Routes2",
"og:description": "Discover how WBC-Routes2 enhances Vue apps with Markdown, Vue components, and SEO metadata.",
"og:image": "http://wi-bg.com/assets/preview.png",
"twitter:image": "http://wi-bg.com/assets/preview-twitter.png"
}
}π§ Behavior and Priority β
WBC-Routes2 resolves metadata using the following priority:
- β
Metadata defined inside the WBC
itemcontent (comp: meta) - π‘ Metadata defined inside the routeβs
metafield - π΄ Fallback defaults (e.g., global config in
config.jsor HTML template)
π Multi-Language Meta via Route β
Just like content, metadata can also be defined per language using language-specific keys.
js
{
path: "/wbc/about",
name: "WBCAboutMultilang",
component: WBC,
props: {
item: {
en: "./docs/about-en.md",
fr: "./docs/about-fr.md"
}
},
meta: {
comp: "meta",
title: {
en: "About WBC",
fr: "Γ propos de WBC"
},
description: {
en: "What is WBC-Routes2? Learn about the plugin and ecosystem.",
fr: "Quβest-ce que WBC-Routes2 ? DΓ©couvrez le plugin et son Γ©cosystΓ¨me."
},
keywords: ["Vue.js", "WBC", "metadata", "localization", "routes"]
}
}π Real-Time Meta Switching (Experimental) β
If your application supports runtime language switching (e.g. via vue-i18n), WBC-Routes2 can reactively update metadata by combining:
- ``route.meta`
- reactive WBC component scope
- DOM
<head>mutation utilities
Note: VuePress may cache some meta values. Use dynamic rendering only in SPA context.
π Use Cases β
- VuePress extensions
- Static site generators
- Developer documentation (like this!)
- CMSs or headless frontends
π Summary β
Using metadata in route definitions helps decouple presentation from configuration. With WBC-Routes2:
- Meta is declarative and centralized
- Pages are better indexed and shared
- Language-specific SEO is easy to manage
- No need to manually tweak HTML head