javascript - Vue router - missing param for named route - Stack Overflow

How can I solve this problem.I have a button which should link me to the view about the object I have c

How can I solve this problem.

I have a button which should link me to the view about the object I have created. For example

   <router-link :to="{ name:DetailView,
                       params:{ id: detail.id}
                     }
                @click="createDetail()> Create Detail
   </router-link>

And in my ponent detail is set after a backend request:

detail:Detail;

createDetail(){
    makeBackendCall().then(detail=>{
        this.detail=detail
    })
}

This is the warning/error I get:

[vue-router] missing param for named route "name:DetailView":
Expected "id" to match "[^\/]+?", but received ""

Obviously the detail ponent is not yet loaded. Is there something I am missing?

How can I solve this problem.

I have a button which should link me to the view about the object I have created. For example

   <router-link :to="{ name:DetailView,
                       params:{ id: detail.id}
                     }
                @click="createDetail()> Create Detail
   </router-link>

And in my ponent detail is set after a backend request:

detail:Detail;

createDetail(){
    makeBackendCall().then(detail=>{
        this.detail=detail
    })
}

This is the warning/error I get:

[vue-router] missing param for named route "name:DetailView":
Expected "id" to match "[^\/]+?", but received ""

Obviously the detail ponent is not yet loaded. Is there something I am missing?

Share Improve this question edited Aug 25, 2020 at 7:58 Julian 36.9k24 gold badges135 silver badges191 bronze badges asked Mar 2, 2019 at 15:41 greedsingreedsin 1,2722 gold badges27 silver badges49 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

You should make a normal html button, and then manually redirect the user after you make your backend object (and use css to style the button)

    <button @click="createDetail()"> Create Detail
    </button>
    createDetail(){
        makeBackendCall().then(detail=>{
            this.$router.push({
                name: DetailView,
                params: {
                    id: detail.id
                }
            })
        })
    }

In the above code, $router is a link to the current active Vue router, and there are also other methods you can call on it, to do differend things

This is a mon mistake when you try to render 'detail.id' for the first time. Probably property 'id' is undefined. So you can do something like this to avoid that warn:

<router-link
    v-if="typeof detail.id !== 'undefined'" ...

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744243903a4564833.html

相关推荐

  • javascript - Vue router - missing param for named route - Stack Overflow

    How can I solve this problem.I have a button which should link me to the view about the object I have c

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信