// 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 Home | About | Contact | 404 Test // views/HomeView.vue Home Page Welcome to the home page! // views/AboutView.vue About Us This is the about page, where you can learn more about us. // views/ContactView.vue Contact Us Feel free to reach out to us! // views/NotFoundView.vue 404 - Page Not Found Oops! The page you are looking for does not exist.
Welcome to the home page!
This is the about page, where you can learn more about us.
Feel free to reach out to us!
Oops! The page you are looking for does not exist.