1. When I return from the sub-routing page to the first-level routing page, there is an error
2. The browser console reported an error as follows
Uncaught (in promise) Error: [vue-router] TypeError: Cannot read property "app" of undefined
3. My code address
https://github.com/libp/littl.
4. Click on the route to achieve normal adjustment, and the page display is also normal, that is, the console reports an error
5.app.vue
<template>
<div id="app">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: "App"
}
</script>
<style lang="scss" rel="stylesheet/scss">
@import "./style/common.scss";
.main {
background: -sharpededed;;
}
</style>
6. Report an error when clicking on the list of articles or recommendations
<el-submenu index="2">
<template slot="title"><i class="el-icon-document"></i></template>
<el-menu-item index="articleList"></el-menu-item>
<el-menu-item index="recommendList"></el-menu-item>
</el-submenu>
7.route.js is as follows
import Vue from "vue"
import Router from "vue-router"
const Index = () => import("/page/index.vue")
const Home = () => import("/page/Home/home.vue")
const Random = () => import("/page/Home/random.vue")
const About = () => import("/page/Home/about.vue")
const Num = () => import("/page/Home/num.vue")
const Nav = () => import("/page/ProgrammerNav/Nav.vue")
const Admin = () => import("/page/Admin/index.vue")
const Adminhome = () => import("/page/Admin/home.vue")
const ArticleList = () => import("/page/Admin/articlelist.vue")
const RecommendList = () => import("/page/Admin/recommendList.vue")
Vue.use(Router)
const scrollBehavior = function (to, from, savedPosition) {
if (savedPosition) {
// savedPosition is only available for popstate navigations.
return savedPosition
} else {
const position = {}
// scroll to anchor by returning the selector
if (to.hash) {
position.selector = to.hash
// specify offset of the element
if (to.hash === ".title") {
position.offset = { y: 100 }
}
if (document.querySelector(to.hash)) {
return position
}
// if the returned position is falsy or an empty object,
// will retain current scroll position.
return false
}
return new Promise(resolve => {
// check if any matched route config has meta that requires scrolling to top
if (to.matched.some(m => m.meta.scrollToTop)) {
// coords will be used if no selector is provided,
// or if the selector didn"t match any element.
position.x = 0
position.y = 0
}
// wait for the out transition to complete (if necessary)
this.app.$root.$once("triggerScroll", () => {
// if the resolved position is falsy or an empty object,
// will retain current scroll position.
resolve(position)
})
})
}
}
export default new Router({
mode: "history",
scrollBehavior,
routes: [
{
path: "/",
component: Index,
name: "index",
redirect: "/home",
children: [
{path: "home", component: Home},
{path: "random", component: Random, meta: { scrollToTop: true }},
{path: "about", component: About, meta: { scrollToTop: true }},
{path: "num/:id", name: "num", component: Num, meta: { scrollToTop: true }}
]
},
{
path: "/nav",
component: Nav
},
{
path: "/dasheng",
component: Admin,
children: [
{path: "/", component: Adminhome},
{path: "/articleList", component: ArticleList, meta: ["", ""]},
{path: "/recommendList", component: RecommendList, meta: ["", ""]}
]
}
// {
// path: "*",
// redirect: "/home"
// }
]
})