我已经设定了路线,如果点击网站上的链接,它将正常运行。但是,当您在该页面上(例如/ aboutUs)并刷新它或只是复制url时,将其粘贴并单击Enter,它将显示“找不到页面”。如何解决?用尽了主意,找不到在任何地方都可以使用的答案
下面的main.js:
Vue.config.productionTip = false;
Vue.use(VueRouter);
Vue.prototype.$careerEmpty = false;
const router = new VueRouter({
mode:'history',
scrollBehavior(to, from, savedPosition){
if (to.hash) {
return { selector: to.hash}
} else if (savedPosition) {
return savedPosition;
} else {
return {x:0, y:0}
}
},
routes
});
new Vue({
router,
render: h => h(App),
}).$mount('#app')
下面的routes.js:
import firstPage from "@/components/Pages/firstPage";
import aboutUsPage from "@/components/Pages/aboutUsPage";
import pageNotFound from "@/components/pageNotFound";
const routes = [
{path: '/', component: firstPage},
{path: '/aboutUs', component: aboutUsPage},
{path: '/404', component: pageNotFound},
{path: '*', redirect: '/404'},
];
export default routes;
您可以使用vue路由器历史记录模式。Check here
Vue.use(路由器,{模式:“历史”});