S
S
Spoon in the brain2020-02-24 21:22:33
Vue.js
Spoon in the brain, 2020-02-24 21:22:33

Why is the root subrouter not loading?

Good evening, I have a problem...
I'll start in order, I created a dynamic router:

{
  path:'/user/:login',
  name:'UserPage',
  component:UserPage,
}

After that, I created the UserProfilePostsCom component , which in turn loads information about the user's posts from the backend, and I placed this component in the UserPage router as a subrouter and made it the root, here is my own code:
{
  path:'/user/:login',
  name:'UserPage',
  component:UserPage,
  children:[
    {
      path:'',
      name:'UserProfilePosts',
      component:UserProfilePostsCom
    }
  ]
}

Just in case, I'll throw off the code of the UserProfilePostsCom component (well, this is the component that loads information about posts from the back):
<template>
    <div class="UserProfilePostsCont">
        <div class="UserProfilePosts">
            <div class="UserProfilePost" v-for="PostData in postsData" :key="PostData.id">
                <hr>
                <p>{{PostData.Content}}</p>
                <hr>
            </div>
        </div>
    </div>
</template>

<script>
export default{
    data: function(){
        return{
            postsData: null
        }
    },
    created(){
        const Login = this.$route.params.login
        this.$axios.post(this.$server+'getposts', {'Login': Login})
       .then(resp=>{
           this.postsData = resp.data.Posts
       })
   }
}
</script>

Well, the UserPage component itself (I will shorten the code as it is very large):
<template>
    <div>
        <li>
            <router-link to="/">Home</router-link>
        </li>
        <div>
            <router-view/>
        </div>
    </div>
</template>

<script>
export default {
    ...
}
</script>

So now I will describe the essence of this problem, when I want to go to the user's page (go with the help, that is, without completely reloading the page) and read his posts, then the UserProfilePostsCom component does not load , so the question is why? Why is this component not loaded in if it is the root subrouter of the UserPage router ? What am I doing wrong?
To be honest, I'm already tired of this problem, and I just can't find a solution, now I'm still throwing screenshots from the developer tools :
1) This screenshot after going through to the user's main page, that is, without a full reboot (SPA and all that... ):
5e541311ca698431117233.png
2) It's very strange here, I take this screenshot after a complete reload of the page and in general everything works, all posts are loaded ...
5e54138f3687d820984843.png
Has anyone encountered such a problem? I will be very glad to your answers!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Drozdov, 2020-02-24
@bagzon

Components are cached and not re-created after the first transition, use hooks at the router, there are 3 hooks, hang on them in the component you need and load the info)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question