|
@@ -0,0 +1,39 @@
|
|
|
+/**
|
|
|
+ * 判断当前应用路由是否匹配到
|
|
|
+ * @param router
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+function getHasRouteMatched(router) {
|
|
|
+ var pathName = location.pathname;
|
|
|
+ var baseName = router.options.base;
|
|
|
+ var pathIndex = pathName.indexOf(baseName);
|
|
|
+
|
|
|
+ if (pathIndex > -1) {
|
|
|
+ var nowPath = pathName.slice(pathIndex + baseName.length);
|
|
|
+ var { route } = router.resolve({
|
|
|
+ path: nowPath,
|
|
|
+ });
|
|
|
+ var hasRouteMatched = route.matched.length > 0;
|
|
|
+ return hasRouteMatched;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 子应用 404 页面拦截
|
|
|
+ * @param router
|
|
|
+ */
|
|
|
+function addNotFindPage(router) {
|
|
|
+ var notFindPage = "/page_error/404.html";
|
|
|
+ router.beforeEach((to, from, next) => {
|
|
|
+ if (to.matched.length === 0) {
|
|
|
+ window.top.location.replace(notFindPage);
|
|
|
+ } else {
|
|
|
+ next();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!getHasRouteMatched(router)) {
|
|
|
+ window.top.location.replace(notFindPage);
|
|
|
+ }
|
|
|
+}
|