Skip to content

Commit

Permalink
fix: Refactor router to dynamic router
Browse files Browse the repository at this point in the history
  • Loading branch information
yeeway committed Jan 15, 2024
1 parent ba399b5 commit 4e779e4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
51 changes: 17 additions & 34 deletions src/dist/router.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ var _About = _interopRequireDefault(require("./views/About.vue"));

var _Info = _interopRequireDefault(require("./views/Info.vue"));

var _Souvenir = _interopRequireDefault(require("./views/Souvenir.vue"));

var _Partners = _interopRequireDefault(require("./views/Partners.vue"));

var _Activities = _interopRequireDefault(require("./views/activities/Activities.vue"));

var _MainStage = _interopRequireDefault(require("./views/activities/MainStage.vue"));
Expand Down Expand Up @@ -47,6 +43,10 @@ var _featuredArticles = _interopRequireDefault(require("./data/featuredArticles.

var _letterToHighSchoolStudents = _interopRequireDefault(require("./data/letterToHighSchoolStudents.json"));

var _Souvenir = _interopRequireDefault(require("./views/Souvenir.vue"));

var _Partners = _interopRequireDefault(require("./views/Partners.vue"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

var routes = [{
Expand Down Expand Up @@ -113,14 +113,26 @@ var routes = [{
path: '/forum/departmentHandbook',
name: '科系手冊',
component: _DepartmentHandbook["default"]
}, {
path: '/forum/departmentHandbook/:department',
name: '科系手冊-科系',
component: _DepartmentHandbook["default"]
}, {
path: '/forum/featuredArticles',
name: '專欄文章',
component: _FeaturedArticles["default"]
}, {
path: '/forum/featuredArticles/:article',
name: '專欄文章-貼文',
component: _FeaturedArticles["default"]
}, {
path: '/forum/letterToHighSchoolStudents',
name: '給高中生的一封信',
component: _LetterToHighSchoolStudents["default"]
}, {
path: '/forum/letterToHighSchoolStudents/:letter',
name: '給高中生的一封信-貼文',
component: _LetterToHighSchoolStudents["default"]
}, {
path: '/partners',
name: '合作夥伴',
Expand All @@ -129,36 +141,7 @@ var routes = [{
path: '/souvenir',
name: '紀念品小舖',
component: _Souvenir["default"]
}]; // add routes for each department under "departmentHandbook" page

_departmentHandbook["default"].map(function (college) {
college.departments.map(function (department) {
routes.push({
path: '/forum/departmentHandBook/' + department.id,
name: department.name,
component: _DepartmentHandbook["default"]
});
});
}); // add routes for each article under "featuredArticles" page


_featuredArticles["default"].map(function (article) {
routes.push({
path: '/forum/featuredArticles/' + article.id,
name: article.title,
component: _FeaturedArticles["default"]
});
}); // add routes for each letter under "letterToHighSchoolStudents" page


_letterToHighSchoolStudents["default"].map(function (letter) {
routes.push({
path: '/forum/letterToHighSchoolStudents/' + letter.id,
name: letter.title,
component: _LetterToHighSchoolStudents["default"]
});
});

}];
var router = (0, _vueRouter.createRouter)({
history: (0, _vueRouter.createWebHistory)('/BikeFestival17th-Frontend/'),
routes: routes
Expand Down
38 changes: 5 additions & 33 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import { createRouter, createWebHistory } from 'vue-router'
import Home from './views/Home.vue';
import About from './views/About.vue';
import Info from './views/Info.vue';
import Souvenir from './views/Souvenir.vue';
import Partners from './views/Partners.vue';

import Activities from './views/activities/Activities.vue';
import MainStage from './views/activities/MainStage.vue';
import DepartmentExpo from './views/activities/DepartmentExpo.vue';
Expand All @@ -13,14 +10,15 @@ import UniversityBlueprint from './views/activities/UniversityBlueprint.vue';
import LifeCrossroads from './views/activities/LifeCrossroads.vue';
import ImmersiveExperience from './views/activities/ImmersiveExperience.vue';
import UnworriedTeaHouse from './views/activities/UnworriedTeaHouse.vue';

import Forum from './views/forum/Forum.vue';
import DepartmentHandbook from './views/forum/DepartmentHandbook.vue';
import FeaturedArticles from './views/forum/FeaturedArticles.vue';
import LetterToHighSchoolStudents from './views/forum/LetterToHighSchoolStudents.vue';
import departmentHandbookData from "./data/departmentHandbook.json";
import featuredArticlesData from "./data/featuredArticles.json";
import letterToHighSchoolStudentsData from "./data/letterToHighSchoolStudents.json";
import Souvenir from './views/Souvenir.vue';
import Partners from './views/Partners.vue';

const routes = [
{ path: '/', name: '首頁', component: Home },
Expand All @@ -39,41 +37,15 @@ const routes = [
{ path: '/activities/unworriedTeaHouse', name: '解憂茶軒', component: UnworriedTeaHouse },
{ path: '/forum', name: '知識論壇', component: Forum },
{ path: '/forum/departmentHandbook', name: '科系手冊', component: DepartmentHandbook },
{ path: '/forum/departmentHandbook/:department', name: '科系手冊-科系', component: DepartmentHandbook },
{ path: '/forum/featuredArticles', name: '專欄文章', component: FeaturedArticles },
{ path: '/forum/featuredArticles/:article', name: '專欄文章-貼文', component: FeaturedArticles },
{ path: '/forum/letterToHighSchoolStudents', name: '給高中生的一封信', component: LetterToHighSchoolStudents },
{ path: '/forum/letterToHighSchoolStudents/:letter', name: '給高中生的一封信-貼文', component: LetterToHighSchoolStudents },
{ path: '/partners', name: '合作夥伴', component: Partners },
{ path: '/souvenir', name: '紀念品小舖', component: Souvenir },
];

// add routes for each department under "departmentHandbook" page
departmentHandbookData.map((college) => {
college.departments.map((department) => {
routes.push({
path: '/forum/departmentHandBook/' + department.id,
name: department.name,
component: DepartmentHandbook
});
});
});

// add routes for each article under "featuredArticles" page
featuredArticlesData.map((article) => {
routes.push({
path: '/forum/featuredArticles/' + article.id,
name: article.title,
component: FeaturedArticles
});
});

// add routes for each letter under "letterToHighSchoolStudents" page
letterToHighSchoolStudentsData.map((letter) => {
routes.push({
path: '/forum/letterToHighSchoolStudents/' + letter.id,
name: letter.title,
component: LetterToHighSchoolStudents
});
});

const router = createRouter({
history: createWebHistory('/BikeFestival17th-Frontend/'),
routes,
Expand Down

0 comments on commit 4e779e4

Please sign in to comment.