router is working with mock endpoints for checking if a page exists
This commit is contained in:
parent
ad5ff8e0a4
commit
b8b23f5448
6 changed files with 94 additions and 3 deletions
12
src/constants/mock-endpoints.js
Normal file
12
src/constants/mock-endpoints.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
//used until real services are available
|
||||||
|
|
||||||
|
const endpoints = {
|
||||||
|
GetRouteInfo: {
|
||||||
|
url: "https://mockey.qa.sagaws.net/service/ISS/Content/RouteInfo",
|
||||||
|
method: "GET",
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export { endpoints };
|
||||||
|
|
||||||
|
|
@ -17,5 +17,22 @@ export default {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
//used for mocked services
|
||||||
|
async mockCallHttpClient(method, endpoint) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
axios({ method: method, url: endpoint, crossDomain: true, responseType: {}})
|
||||||
|
.then((response) => {
|
||||||
|
return resolve(response);
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
console.error(error);
|
||||||
|
return reject(error.response);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
9
src/layouts/error-404/error-404.vue
Normal file
9
src/layouts/error-404/error-404.vue
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<template>
|
||||||
|
404: Page Not Found
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'error-404'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
9
src/layouts/vehicle-make/vehicle-make.vue
Normal file
9
src/layouts/vehicle-make/vehicle-make.vue
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
<template>
|
||||||
|
Vehicle Make Placeholder
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'vehicle-make'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
17
src/layouts/welcome-page/welcome-page.vue
Normal file
17
src/layouts/welcome-page/welcome-page.vue
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
<template>
|
||||||
|
<p>Welcome Page Placeholder</p>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'welcome-page'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
p {
|
||||||
|
font-weight: bold;
|
||||||
|
color: purple;
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import { storeActions } from "@/constants/store-actions";
|
|
||||||
import { createWebHistory, createRouter } from "vue-router";
|
import { createWebHistory, createRouter } from "vue-router";
|
||||||
|
import { lazyLoadComponent } from "./dynamic-routing/component-loader";
|
||||||
|
import { endpoints } from "../constants/mock-endpoints";
|
||||||
|
import globalMethods from "@/global-methods";
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
|
|
@ -12,6 +14,11 @@ const routes = [
|
||||||
}
|
}
|
||||||
const routeData = await GetRouteInfoFromPageName(to.query.issPage);
|
const routeData = await GetRouteInfoFromPageName(to.query.issPage);
|
||||||
|
|
||||||
|
if(routeData[0].name.toLowerCase() === "error")
|
||||||
|
{
|
||||||
|
throw("Page not found!")
|
||||||
|
}
|
||||||
|
|
||||||
// Add our dynamic route.
|
// Add our dynamic route.
|
||||||
router.addRoute({
|
router.addRoute({
|
||||||
path: routeData[0].path, // Always the same path, because we control it with query strings.
|
path: routeData[0].path, // Always the same path, because we control it with query strings.
|
||||||
|
|
@ -19,7 +26,6 @@ const routes = [
|
||||||
component: routeData[0].component,
|
component: routeData[0].component,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Assign current query string parameters, as well as our fmgPage one.
|
// Assign current query string parameters, as well as our fmgPage one.
|
||||||
next({
|
next({
|
||||||
name: routeData[0].name,
|
name: routeData[0].name,
|
||||||
|
|
@ -29,7 +35,7 @@ const routes = [
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
await GoToStartOn404(next);
|
GoToStartOn404(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
@ -42,9 +48,15 @@ const router = createRouter({
|
||||||
// Get route information by page name.
|
// 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.
|
// This will reach out to the Cms and there is a 1:1 relationship between page names and route names.
|
||||||
async function GetRouteInfoFromPageName(pageName) {
|
async function GetRouteInfoFromPageName(pageName) {
|
||||||
|
|
||||||
|
//move to store actions later?
|
||||||
|
/*
|
||||||
const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, {
|
const response = await store.dispatch(storeActions.GET_ROUTE_INFO_ACTION, {
|
||||||
pageName: pageName,
|
pageName: pageName,
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
const response = await globalMethods.mockCallHttpClient("GET", endpoints.GetRouteInfo.url + "?route=" + pageName)
|
||||||
const jsonFromResponse = JSON.parse(response.data.Result);
|
const jsonFromResponse = JSON.parse(response.data.Result);
|
||||||
let routeData = [];
|
let routeData = [];
|
||||||
|
|
||||||
|
|
@ -100,4 +112,19 @@ function getNavigationMap(scenario, currentRoute) {
|
||||||
return matchedQueryValue[0];
|
return matchedQueryValue[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function GoToStartOn404(next) {
|
||||||
|
const errorPageName = "error-404"
|
||||||
|
router.addRoute({
|
||||||
|
path: "/",
|
||||||
|
name: errorPageName,
|
||||||
|
component: lazyLoadComponent(errorPageName),
|
||||||
|
});
|
||||||
|
|
||||||
|
next({
|
||||||
|
name: errorPageName,
|
||||||
|
query: {issPage: errorPageName },
|
||||||
|
});
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Loading…
Reference in a new issue