Greetings!
I’m trying to implement re-routing based on data: if the list has only a single document, then I’m creating a route to a specific component, skipping the list picker.
Here’s what I have in the js/routes.js file:
{
path: '/ev-logbook-entry/id/:Id/spots/:MaxSpots/name/:Name/',
component: EVLogbookEntry,
},
{
path: '/ev-logbook/',
async: function (routeTo, routeFrom, routeResolve, reject) {
<...>
if (docs.length === 1) {
var spot = docs[0];
routeResolve(
{
component: EVLogbookEntry,
},
{
context: {
Id: spot._id,
MaxSpots: spot.max_spots,
Name: spot.name,
}
}
);
} else {
routeResolve(
{
component: EVLogbookRouter,
},
{
context: {
lat: position.coords.latitude,
lon: position.coords.longitude,
accuracy: position.coords.accuracy,
EVPlaces: docs,
}
}
);
}
Everything works great except for the case when I call the EVLogBookEntry directly using a hyperlink. As a result of this, I have to use the following code in the EVLogBookEntry:
<script>
export default {
data: function() {
var self = this;
console.log("self in data function:");
console.log(self);
var dao = {};
if (self.Id) {
dao['Id'] = self.Id;
dao['Name'] = self.Name;
dao['MaxSpots'] = self.MaxSpots;
} else {
dao['Id'] = self.$route.params.Id;
dao['Name'] = self.$route.params.Name;
dao['MaxSpots'] = self.$route.params.MaxSpots;
}
return {
sequence: [...Array(Number(dao.MaxSpots)+1).keys()],
id: dao.Id,
name: dao.Name,
};
},
It seems that the parameters are coming differently, depending on how I call this template. Another problem is escaping (URI schema, etc), but that’s another topic.
How can I get rid of that if and dao object?