I am coding a restaurant review project with Django REST and Vue.js. I use google place ID as PK for my restaurants since Google Place ID are unique and I use Google Place Autocomplete in my project.
So basically I have an autocomplete that get a restaurant Place ID whenever the user select it.
Then I want to redirect automatically to another route where I will fetch all the reviews for that restaurant with an API, (/api/restaurant_review/Google Place ID/), using that Google Place ID.
This is my navbar component:
<template>
<div class="collapse navbar-collapse flex-row justify-content-end">
<vue-google-autocomplete
id="map"
class="form-control mr-sm-2"
placeholder="Find a restaurant"
v-on:placechanged="getAddressData"
country="fr"
types="establishment"
></vue-google-autocomplete>
</template>
<script>
import VueGoogleAutocomplete from "vue-google-autocomplete";
export default {
name: "NavbarComponent",
components: { VueGoogleAutocomplete },
data() {
return {
requestUser: null,
addressData: ""
};
},
created() {
this.setRequestUser();
},
methods: {
getAddressData(addressData, placeResultData) {
this.placeResultData = placeResultData;
this.addressData = addressData;
this.$router.push({ name: "reviews", params: { id : this.placeResultData.place_id }})
}
}
};
</script>
For now I made a dummy "reviews" view that only shows an "Hello World" message. Redirection is working fine but I can't find a way to check if my "id" is available in my reviews view. And I don't know if it is the right way to do so either. As well, is it possible to pass more than one params?