pickstack

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 --yes
Customize in the configurator

Packages it adds

PackageVersionType
vue-router^5.5.1runtime

New files

src/router/index.ts
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;
src/views/AboutView.vue
<template>
  <section class="page">
    <h1 class="title">About</h1>
    <p class="text">Built with Vue 3, Vite, TypeScript, Vue Router.</p>
  </section>
</template>
src/views/HomeView.vue
<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

src/App.vue (changed)
 <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>  
src/main.ts (changed)
 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