因此,我有一个问题,即路线已经太晚了,并且存在,但是当我重新加载页面时,它们不会显示,所以我猜测它们的加载太晚了。 I have the following code in the index.ts of the router:
fetch('http://localhost:8000/api/test/all').then((response) => response.json())
.then((data) => {
if (data) {
for (let route of data) {
router.addRoute({path: '/' + route.name, name: route.name, component: () => import('../views/TestView.vue')})
}
};
});
Is there some sort of lifecycle hook, or can I make it somehow to wait for the result before navigating to the page? 我尝试了Beforerouteenter,但它没有起作用。 我在app.vue
中尝试的。router.beforeEach((to, from, next) => {
fetch('http://localhost:8000/api/test/all').then((response) => response.json())
.then((data) => {
if (data) {
for (let route of data) {
router.addRoute({path: '/' + route.name, name: route.name, component: () => import('./views/TestView.vue')})
}
next()
};
});
})
但是当我刷新 /xy时,我会得到一个空白网站,因为它找不到 /xy