admin管理员组文章数量:1355535
I'm trying to convert a react project to vue, for educational purposes only. Instead of using RouterLink, I used a regular anchor like:
<li><a href='#' @click="handleNavMenu('/URL')">Link 1</a></li>
I'm testing lazy loading and this aproach didn't work. I read lot of posts about similar problem but none of them seems to repeat this similar behavior.
At the end, my solution for this was to add prevent to click event:
<li><a href='#' @click.prevent="handleNavMenu('/URL')">Link 1</a></li>
As I couldn't find anything about this on documentation, I would like to know if it something I missed.
here goes a complete code:
route.js
const routes = [
{
path: '/',
name: 'home',
component: HomeView,
},
{
path: '/avaliacao-emp',
name: 'avaliacaoEmp',
// route level code-splitting
// this generates a separate chunk (About.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: ()=> import('../views/avaliacao-emp/index.vue'),
},];
App.vue
const router = useRouter();
const handleNavMenu = async (url) => {
const failure = await router.push(url)
console.log(failure)
}
<template>
<li><a href='#' @click.prevent="handleNavMenu('/URL')">Link 1</a></li>
</template>
Dependencies:
"dependencies": {
"pinia": "^3.0.1",
"vue": "^3.5.13",
"vue-router": "^4.5.0"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",
"prettier": "3.5.3",
"sass-embedded": "^1.86.0",
"vite": "^6.2.1",
"vite-plugin-vue-devtools": "^7.7.2"
}
本文标签: vuejsVue router lazy loading not renderingStack Overflow
版权声明:本文标题:vue.js - Vue router lazy loading not rendering - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743973500a2570785.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论