Remove calls to RouteInfo and GetHomePage in router.
This commit is contained in:
parent
438e63e780
commit
0998285fd8
2 changed files with 32 additions and 24 deletions
|
|
@ -9,6 +9,7 @@ import { queryStrings } from "@/constants/query-strings";
|
|||
import { getQuerystringParameter } from "@/helpers/querystring-helper";
|
||||
import { getDeviceIdValue } from "@/helpers/heritage-integration/cookie-helper";
|
||||
import { showFmgLoadingModal } from "@/helpers/loading-modal-helper";
|
||||
import { fmgPageValues, homepageName } from "@/router/router-constants/fmgPage-values";
|
||||
|
||||
// Heritage integration
|
||||
import { isSavedSessionStillActive } from "@/helpers/heritage-integration/session-helper";
|
||||
|
|
@ -48,7 +49,7 @@ const routes = [
|
|||
// If the saved session has timed out, clear the session, execute 404 logic.
|
||||
if (getFunnelCookie() !== null && !isSavedSessionStillActive()) {
|
||||
await baseMixin.methods.dispatchStoreAction(storeActions.RESET_STATE);
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// Intercept all navigation if a submitted order exists in storage
|
||||
|
|
@ -100,14 +101,18 @@ const routes = [
|
|||
}
|
||||
|
||||
if (!arePagePrerequisitesValid(component)) {
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
|
||||
}
|
||||
|
||||
if (!isExistingFmgPageName(to.query.fmgPage)) {
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// Get route info for the given url. Names will have a 1:1 relationship with names in the Cms.
|
||||
const routeData = await GetRouteInfoFromPageName(to.query.fmgPage);
|
||||
const routeData = GetRouteInfoFromPageName(to.query.fmgPage);
|
||||
|
||||
// Add our dynamic route.
|
||||
router.addRoute({
|
||||
|
|
@ -124,7 +129,7 @@ const routes = [
|
|||
.components.default();
|
||||
|
||||
if (!arePagePrerequisitesValid(nextComponent)) {
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
|
||||
// Assign current query string parameters, as well as our fmgPage one.
|
||||
|
|
@ -137,7 +142,7 @@ const routes = [
|
|||
console.log(error);
|
||||
|
||||
// If we don't have a route, go to our 404 page.
|
||||
await GoToFunnelStartOn404(next);
|
||||
GoToFunnelStartOn404(next);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
@ -355,31 +360,26 @@ function navigateToUrl(url, optionalQuery = {}) {
|
|||
}
|
||||
|
||||
// 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.
|
||||
async function GetRouteInfoFromPageName(pageName) {
|
||||
const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, {
|
||||
pageName: pageName,
|
||||
});
|
||||
const jsonFromResponse = JSON.parse(response.data.Result);
|
||||
let routeData = [];
|
||||
// This will no longer reach out to the Cms. There is a 1:1 relationship between page names and route names and layouts.
|
||||
function GetRouteInfoFromPageName(pageName) {
|
||||
// check if pagename is a valid route/component
|
||||
if (!isExistingFmgPageName(pageName)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Add our route data and return our array.
|
||||
Object.keys(jsonFromResponse).forEach((key) => {
|
||||
routeData.push({
|
||||
const routeData = [
|
||||
{
|
||||
path: "/",
|
||||
name: `${key}`,
|
||||
component: lazyLoadComponent(jsonFromResponse[key].LayoutName),
|
||||
});
|
||||
});
|
||||
name: pageName,
|
||||
component: lazyLoadComponent(pageName),
|
||||
},
|
||||
];
|
||||
|
||||
return routeData;
|
||||
}
|
||||
|
||||
// Go to our start page on a 404.
|
||||
async function GoToFunnelStartOn404(next) {
|
||||
const apiResponse = await store.dispatch(storeActions.GET_HOMEPAGE_NAME);
|
||||
const homepageName = apiResponse.data.Result;
|
||||
|
||||
function GoToFunnelStartOn404(next) {
|
||||
// Put item on the bus
|
||||
eventBus.addEventToBus(
|
||||
globalEvents.Categories.GLOBAL_ALERT,
|
||||
|
|
@ -398,6 +398,12 @@ async function GoToFunnelStartOn404(next) {
|
|||
});
|
||||
}
|
||||
|
||||
function isExistingFmgPageName(pageName) {
|
||||
const names = Object.values(fmgPageValues);
|
||||
|
||||
return names.some((name) => name === pageName);
|
||||
}
|
||||
|
||||
// Checks arePagePrerequisitesValid on the component passed in.
|
||||
function arePagePrerequisitesValid(component) {
|
||||
return component.default.methods.arePagePrerequisitesValid();
|
||||
|
|
|
|||
|
|
@ -22,4 +22,6 @@ const fmgPageValues = {
|
|||
CONFIRMATION: "confirmation",
|
||||
};
|
||||
|
||||
export { fmgPageValues };
|
||||
const homepageName = fmgPageValues.VEHICLE;
|
||||
|
||||
export { fmgPageValues, homepageName };
|
||||
|
|
|
|||
Loading…
Reference in a new issue