IT이야기

다시 로드한 후 vue-temp가 잘못된 매개 변수를 설정함

cyworld 2022. 3. 21. 09:04
반응형

다시 로드한 후 vue-temp가 잘못된 매개 변수를 설정함

있습니다

// routes.js
{ path: '/posts', name: 'Posts', component: PostsView },
{
    path: '/post/:post_id',
    name: 'PostRead',
    component: PostReadView,
},
{
    path: '/post/cu/:post_id?',
    name: 'PostCreateUpdate',
    component: PostCreateUpdateView,
},
// PostCreateUpdate.vue
mounted: function() {
    if( this.$route.params.post_id ) {
        this.$store.dispatch('getPost', this.$route.params.post_id);
    }
},

다음과 같은 라우터 링크를 통해 PostCreateUpdate에 액세스할 때

<router-link :to="{ name: 'PostCreateUpdate' }">Create</router-link>

Vue Devtools의 매개 변수가 설정되지 않았지만 URL을 다시 로드하거나 하드 코딩하여 URL에 액세스할 때 문제가 없음/post/cu/골격(내 생각에)은 후행 슬래시를 제거하고 치료한다.cu일부로서/post/매개변수, 따라서 로드PostRead, 와 함께.post_id=cu내가 원하지 않는 걸 주는 거야

당신은 항상 당신의 가장 제한적인 URI를 먼저 선언할 필요가 있다.주문은 중요한데, 왜냐하면 Vue Router는 당신의 경로를 거치게 될 것이고, 가장 먼저 일치하는 것을 고르시오.

뒤집기/post/:post_id노선과/post/cu/:post_id?원:

// routes.js
{ path: '/posts', name: 'Posts', component: PostsView },
{
    path: '/post/cu/:post_id?',
    name: 'PostCreateUpdate',
    component: PostCreateUpdateView,
},
{
    path: '/post/:post_id',
    name: 'PostRead',
    component: PostReadView,
},

참조URL: https://stackoverflow.com/questions/62734926/vue-router-sets-wrong-parameter-after-reloading

반응형