javascript - 当我重新加载页面时,我的 vue-router 不会加载组件,但在转换时会加载

标签 javascript vue.js vue-router

应用程序.vue:

<template>
  <div id="app">
    <header-section />
    <router-view class="child-container" />
    <bottom-nav v-if="!isAuthRoute" />
  </div>
</template>

我的router.js:


export default new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [{
        path: '/',
        name: 'Authenticate',
        component: Authenticate,
    }, {
        path: 'conversations',
        name: 'ConversationsList',
        component: ConversationsList
    }, {
        path: 'conversations/:ConversationId',
        component: ConversationDetail,
        children: [{
            path: '',
            name: 'ConversationDetailHighlights',
            component: ConversationDetailHighlights

        }, {
            path: 'transcript',
            name: 'ConversationDetailFullTranscript',
            component: ConversationDetailFullTranscript

        }]
    }],

    scrollBehavior() {
        return { x: 0, y: 0 }
    }
});

当我单击链接转到 /conversations 时,它加载正常。但是当我直接在浏览器中加载 /conversations 时,它不会加载 ConversationsList 组件:

enter image description here

最佳答案

您是否尝试使用路径:'/conversations'?我很确定只有当路由是 path: '/' 的路由的子级时才会省略斜杠前缀

关于javascript - 当我重新加载页面时,我的 vue-router 不会加载组件,但在转换时会加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57132501/

相关文章:

javascript - 在 Vue 中按值拼接数组?

javascript - 使用 Vuejs 搜索过滤器

vuejs2 - 如何在 VueJs 中创建可重用的组件?

javascript - 当前元素数据属性中的访问循环索引 - VueJS

javascript - 如何在Vue.js中使用filterBy

javascript - VueJS 中的菜单折叠

Javascript 语法错误被吞并隐藏在 async/await 函数中

javascript - 使用 jQuery 的 D3.js 图的节点搜索栏

javascript - 使用原型(prototype)时停止 JavaScript 中的枚举

javascript - 如何使用 Javascript 显示我最新推文状态的链接?