Vue + Vue Router
The official Vue router; pages live in src/views. This page shows exactly what pickstack adds to a Vue project for Vue Router: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.
$ npm create pickstack@latest my-app -- --framework vue --modules vue-router --yesCustomize in the configurator
Packages it adds
| Package | Version | Type |
|---|---|---|
vue-router | ^5.5.1 | runtime |
New files
import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: "/",
name: "home",
component: HomeView,
},
{
path: "/about",
name: "about",
component: () => import("../views/AboutView.vue"),
},
],
});
export default router;
<template>
<section class="page">
<h1 class="title">About</h1>
<p class="text">Built with Vue 3, Vite, TypeScript, Vue Router.</p>
</section>
</template>
<script setup lang="ts">
import CounterCard from "../components/CounterCard.vue";
</script>
<template>
<section class="page">
<h1 class="title">my-app</h1>
<CounterCard />
</section>
</template>
Changes to existing files
<script setup lang="ts">+import { RouterLink, RouterView } from "vue-router";−import CounterCard from "./components/CounterCard.vue"; </script> <template> <main class="app">+ <nav class="nav">+ <RouterLink class="link" to="/">Home</RouterLink>+ <RouterLink class="link" to="/about">About</RouterLink>+ </nav>+ <RouterView />− <h1 class="title">my-app</h1>− <CounterCard /> </main> </template>
import { createApp } from "vue"; import App from "./App.vue";+import router from "./router"; import "./assets/main.css"; +const app = createApp(App);+ +app.use(router);+ +app.mount("#app");−createApp(App).mount("#app");
Project files
.gitignoreREADME.mdenv.d.tsindex.htmlpackage.jsonsrc/App.vuesrc/assets/main.csssrc/components/CounterCard.vuesrc/main.tssrc/router/index.tssrc/views/AboutView.vuesrc/views/HomeView.vuetsconfig.app.jsontsconfig.jsontsconfig.node.jsonvite.config.ts