I want to know if it's possible to send a URL with a query to a component page?
For example, this is the URL /physicians/?apptId=123&npi=123456789 and I want it to go to BookAnAppointment.vue. I know it works if I have a route defined like this /physicians/:npi?apptId=123 but that's not what I want.
On the PhysicianLanding page if I click the "Book" button it will add the params to the URL but I can't figure out how to send it to the BookAnAppointment component.
router/index.js
import Vue from 'vue'
import Router from 'vue-router'
import PhysicianLanding from '@/components/PhysicianLanding'
import PhysicianProfile from '@/components/PhysicianProfile'
import BookAnAppointment from '@/components/BookAnAppointment'
Vue.use(Router)
export default new Router({
routes: [
{
path: '/physicians',
component: PhysicianLanding
},
{
path: '/physicians/profile/:url',
component: PhysicianProfile
},
{
path: '/physicians/:npi',
component: BookAnAppointment,
props: true
}
]
})
src/components/PhysicianLanding.vue
<template>
<div class="container">
<h1>{{ msg }}</h1>
<!-- I know this works -->
<button type="button" @click="$router.push({ path: '/physicians/' + physicianNpi, query: { appt_id: apptId }})">Book an Appointment</button>
<!-- I want this one to work -->
<button type="button" @click="$router.push({ path: '/physicians/', query: { appt_id: apptId, npi: physicianNpi }})">Book</button>
</div>
</template>
<script>
export default {
name: 'PhysicianLanding',
data () {
return {
msg: 'Welcome to the physicians landing page',
apptId: '05291988',
physicianNpi: '1346264132'
}
}
}
</script>
src/components/BookAnAppointment.vue
<template>
<div class="container">
<h1>Book an Appointment</h1>
<p>This is where you will book an appointment</p>
<h2>Query Params</h2>
<p>appt_id is {{ $route.query.appt_id }}</p>
<button type="button" @click="$router.push({ path: '/physicians' })">Go back</button>
</div>
</template>
<script>
export default {
name: 'BookAnAppointment',
props: ['npi'],
created () {
console.log('npi is ' + this.$route.params.npi)
console.log('appt_id is ' + this.$route.query.appt_id)
},
data () {
return {}
}
}
</script>