Vue Query get parameters as an array

12 Views Asked by At

Context

I have a Vue application that needs to render scopes which are a query parameter, for example an unencoded version of the query would be such as:

https://example.com/authorize?scope[0]=Users.read&scope[1]=openid...

The issue I am running into, is grabbing these scope parameters as an array in vue-router.

// returns null, but should be ['Users.read', 'openid']
const scopes = computed(() => route.query.scopes) 
// returns 'Users.read'
const scope0 = computed(() => route.query['scope[0]']) 

The problem

If one has an array in my url's query, how does one get that array in vue-router?

Alternative Solution

My current solution, is to iterate over Object.entites, and select all keys that match the RegEx pattern. While this works, it's certainly not ideal. Further, this method doesn't maintain the order of the array, luckily for my current use case, I doesn't care about sorting/order.

Is there a way that Vue Router can be instructed to convert an array of query parameters into an array?

0

There are 0 best solutions below