Vue-router: Optional parameters are dropped in named nested routes

Created on 15 Mar 2018  路  6Comments  路  Source: vuejs/vue-router

Version

3.0.1

Reproduction link

https://codepen.io/wrrrn/pen/GxqmOb
http://jsfiddle.net/7a31maev/1/

Steps to reproduce

I've linked to what the current router code is. The issue is simple, so I hope I'm missing something obvious.

What is expected?

When the :paramOptional is set, and child route is pushed to, the path will look as such -
'/search/paramOne/paramOptional/paramTwo/show-modal'

What is actually happening?

When navigated to, the child removes the paramOptional. The resulting url is -
'/search/paramOne/paramTwo/show-modal'

discussion has PR has workaround needs RFC

Most helpful comment

Adding a this.$router.push({name:'ShowModal', params: {paramOptional: this. paramOptionalData}}) fixes the issue but makes me sad.

All 6 comments

Adding a this.$router.push({name:'ShowModal', params: {paramOptional: this. paramOptionalData}}) fixes the issue but makes me sad.

Edited to add an actual repro.

Thanks for writing this one up. I was just about ready to do it myself but found yours :)

I'm wanting to add an optional parameter at the start of my app (/admin?) to control some admin functionality. For now I'm just using your workaround on adding this in the params.

Let me know if I can help at all

you can work on a fix for this :)

I've created a PR for this :) https://github.com/vuejs/vue-router/pull/2538

@ElkeCodes Does this PR also work for this use case?
/search/:a/(test/:b)?/:c
http://jsfiddle.net/wf517tdu/1/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thomas-alrek picture thomas-alrek  路  3Comments

mitar picture mitar  路  3Comments

saman picture saman  路  3Comments

Atinux picture Atinux  路  3Comments

druppy picture druppy  路  3Comments