Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Navigating through the File Tree and Loading Folders from the URL Chapter 5

for (let entry of response.entries) {
// Check ".tag" prop for type
if(entry['.tag'] == 'folder') {
structure.folders.push(entry);
} else {
structure.files.push(entry);
}
}
this.path = path;
this.structure = structure;
this.isLoading = false;
})
.catch(error => {
console.log(error);
});
}

As you navigate through your app, it should be updating the URL to include the current


folder path.


However, what you will find when you press refresh with a folder; is that the URL resets to


just having a hash with no folder afterward as it is being reset by the empty path passed in
via the method in the created() function.


We can remedy this by passing in the current hash to the getFolderStructure within the


created function, however, there will be a few checks and error catching we will need to


do if we do this.


First, when calling window.location.hash, you also get the hash returned as part of the


string, so we will need to remove that. Second, we need to handle the instance of an


incorrect URL, should the user enter an incorrect path or the folder gets moved. Lastly, we
need to let the user use the back and forward buttons (or keyboard shortcuts) in their


browsers.

Free download pdf