Pre-Caching Other Folders and Files for Faster Navigation Chapter 7
let path = (window.location.hash.substring(1) || ''),
breadcrumb = [],
slug = '',
parts = path.split('/');
for (let item of parts) {
slug += item;
breadcrumb.push({'name': item || 'home', 'path': slug});
slug += '/';
}
state.path = path
state.breadcrumb = breadcrumb;
},
/**
* Cache a folder structure
* @param {object} state The state objet of the store
* @param {object} payload An object containing the slug and data to
store
*/
structure(state, payload) {
state.structure[payload.path] = payload.data;
}
}
});
We furthermore move to the Vue app:
/**
* The Vue app
*/
const app = new Vue({
el: '#app',
// Initialize the store
store,
// Update the current path on page load
mounted() {
store.commit('updateHash');
}
});