vue3:
npm i vue-router@4 --save
创建router文件夹,放入index.js(懒加载)
import { createRouter, createWebHashHistory } from "vue-router";
const routes = [
{
path: "/",
// name: "start",
component: () =>
import(/* webpackChunkName: "about" */ "../view/start.vue"),
},
{
path: "/helloworld",
name: "HelloWorld",
component: () =>
import(/* webpackChunkName: "about" */ "../components/HelloWorld.vue"),
},
];
const router = createRouter({
history: createWebHashHistory(),
routes,
});
export default router;
main.js:
import router from "./router/router.js";
app.use(router)
App.vue:
<router-view></router-view>