// main.js (or main.ts) - Vue Router Setup import { createApp } from 'vue'; import { createRouter, createWebHistory } from 'vue-router'; import App from './App.vue'; import HomeView from './views/HomeView.vue'; import AboutView from './views/AboutView.vue'; import ContactView from './views/ContactView.vue'; import NotFoundView from './views/NotFoundView.vue'; // 1. Define route components (imported from .vue files) // 2. Define your routes array const routes = [ { path: '/', name: 'Home', component: HomeView }, { path: '/about', name: 'About', component: AboutView }, { path: '/contact', name: 'Contact', component: ContactView }, // Catch-all route for 404 - MUST be last { path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFoundView } ]; // 3. Create the router instance const router = createRouter({ history: createWebHistory(), // Use HTML5 history mode (requires server config for direct access) routes, }); // 4. Create and mount the Vue app, making it router-aware const app = createApp(App); app.use(router); app.mount('#app'); // App.vue - Root Component with Router Links and View // views/HomeView.vue // views/AboutView.vue // views/ContactView.vue // views/NotFoundView.vue