Skip to content

Commit

Permalink
Merge pull request #28 from gdsc-ncku/yeeway
Browse files Browse the repository at this point in the history
fix: update Breadcrumb.vue to handle dynamic route parameters
  • Loading branch information
蘇奕幃 Alex Su committed Jan 22, 2024
2 parents e4c2a05 + 6948b49 commit 618e12b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
5 changes: 3 additions & 2 deletions public/bike.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 29 additions & 5 deletions src/components/Breadcrumb.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
</template>

<script>
import departmentHandbookData from '../data/departmentHandbook.json';
import featuredArticlesData from '../data/featuredArticles.json';
export default {
data() {
return {
Expand All @@ -34,12 +37,33 @@ export default {
if (this.$route.params) {
const dynamicParam = Object.values(this.$route.params)[0];
// console.log(dynamicParam);
console.log(dynamicParam);
if (dynamicParam) {
this.breadcrumbs.push({
to: this.$route.path,
label: dynamicParam,
});
const targetDepartment = departmentHandbookData.map((college) => {
return college.departments.find((department) => {
return department.id === dynamicParam;
});
}).filter(Boolean)[0]
// console.log(targetDepartment);
const targetArticle = featuredArticlesData.find((article) => {
return article.id === dynamicParam;
})
// console.log(targetArticle);
if (targetDepartment) {
this.breadcrumbs.push({
to: this.$route.path,
label: targetDepartment.name,
});
} else if (targetArticle) {
this.breadcrumbs.push({
to: this.$route.path,
label: targetArticle.title,
});
} else {
// error handling
}
}
// console.log(this.breadcrumbs);
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/featuredArticles.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"id": "selfLearnin_1",
"id": "selfLearning_1",
"title": "真假新聞分不清?不私藏網路新聞指南!",
"category": "自學力",
"author": "林盈辰",
Expand Down

0 comments on commit 618e12b

Please sign in to comment.