diff --git a/src/router/index.js b/src/router/index.js index d2c335ca7..924ac5965 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -1,6 +1,8 @@ import { createWebHistory, createRouter } from "vue-router"; import { storeActions } from "@/constants/store-actions.js"; import { lazyLoadComponent } from "@/router/dynamic-routing/component-loader.js"; +import { routingTable } from "@/router/router-constants/routing-table.js"; +import { fmgPageValues } from '@/router/router-constants/fmgPage-values.js'; import ComponentTest from "@/layouts/component-test/component-test.vue"; import LoaderDemo from "@/layouts/loader-demo/loader-demo.vue"; import NotFound from "@/layouts/not-found/not-found.vue"; @@ -65,22 +67,37 @@ const routes = [ }, ]; + const router = createRouter({ history: createWebHistory("/fmg/"), routes, }); -router.navigate = (scenario, optionalQuery, optionalParams) => -{ +router.navigate = (scenario, currentRoute, optionalQuery, optionalParams) => { + if (!scenario) { + console.error("No scenario provided, navigating to 404 page."); + } + + // Match our maps up and navigate if we have a destination. + const matchingScenarioMap = router.getNavigationMap(scenario, currentRoute); + + if (matchingScenarioMap.destinationFmgPageValue !== undefined) { + router.push({ + path: '/', query: Object.assign(currentRoute.query, { fmgPage: matchingScenarioMap.destinationFmgPageValue }) + }); + } } -router.getNavigationMap = (scenario, currentRoute) => -{ +router.getNavigationMap = (scenario, currentRoute) => { const fmgPageValue = currentRoute.query.fmgPage; - + const matchedQueryValue = routingTable.filter(item => (item.fmgPageValue === fmgPageValue) && item.maps.filter(map => map.scenario === scenario).length > 0).map(m => m.maps.filter(map => map.scenario === scenario)); + return matchedQueryValue[0][0]; } + + + // Get route information by page name. // This will reach out to the Cms and there is a 1:1 relationship between page names and route names. function GetRouteInfoFromPageName(pageName) { diff --git a/src/router/router-constants/routing-table.js b/src/router/router-constants/routing-table.js index 410665630..584161f43 100644 --- a/src/router/router-constants/routing-table.js +++ b/src/router/router-constants/routing-table.js @@ -1,4 +1,4 @@ -import { fmgPageValues } from '@/router/router-constants/fmg-page-values'; +import { fmgPageValues } from '@/router/router-constants/fmgPage-values'; import { navigationScenarios } from '@/router/router-constants/navigation-scenarios'; const routingTable = [ @@ -7,7 +7,8 @@ const routingTable = [ maps: [ { scenario: navigationScenarios.SELECTED_YEAR, destinationFmgPageValue: fmgPageValues.VEHICLE_MAKE } ] - } + }, + ] export { routingTable }; \ No newline at end of file