Vue Router Install करना
Vue Router वह official routing library है जो URLs को components से map करती है।
In this page:
Syntax
npm install vue-router@4
Vue Router Install करना
एक project में इसे npm install vue-router@4 से install करें, या create-vue से scaffold करते वक्त add करें। createRouter और एक history mode से एक router बनाएँ, फिर इसे app.use(router) से register करें। CDN से यह VueRouter global की तरह available है।
Note:
clean URLs के लिए createWebHistory चुनें या जब आप server configure न कर सकें createWebHashHistory।
उदाहरण: Installing Vue Router
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
$ npm install vue-router@4
// main.js
import { createApp } from "vue";
import { createRouter, createWebHistory } from "vue-router";
import App from "./App.vue";
const router = createRouter({ history: createWebHistory(), routes: [] });
createApp(App).use(router).mount("#app");
</body>
</html>
⚠️ Run this in your own terminal or Node.js environment.
Live Example
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- Vue 3 के लिए vue-router 3 install करना
- app.use(router) भूल जाना
- server fallback rules के बिना web history इस्तेमाल करना
चैप्टर सारांश
- npm install vue-router@4 से install करें
- createRouter router बनाता है
- app.use(router) इसे install करता है
- एक history mode चुनें
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: