-
Notifications
You must be signed in to change notification settings - Fork 5
Custom init data
Lars van Braam edited this page Nov 17, 2017
·
1 revision
The init call should contain the routes object, this object defines the default landing route and the not found route. Sometimes you might want to add custom data to this init call that is project specific. This can be done by subscribing to the init mutation and passing along your data. Your example init call response could look like this:
{
"statusCode": 200,
"data": {
"routes": {
"landing": "/home",
"notFound": "/page-not-found"
},
"user": {
"firstName": "John",
"lastName": "Doe"
}
}
}
In the src/control/startUp.js
file you can add the following piece of code before the vue-block-system plugin is initialized:
...
// Subscribe to the mutation so we can store the init data in other stores as well!
const unSubscribe = store.subscribe((mutation) => {
if (mutation.type === 'init/setData') {
// un-subscribe after we received the setData mutation
unSubscribe();
// commit the data to the desired stores
store.commit(`user/${SET_USER}`, mutation.payload.user);
}
});
...