M
M
Mike2018-08-11 20:37:27
Vue.js
Mike, 2018-08-11 20:37:27

How to return to the first page from pagination?

I have an App-header.vue component and a BlogFeed.vue component. BlogFeed.vue posts with pagination. I can't get back to the first page from pagination. For example, while in 3 <<1...2... 3 ...4...5>> I click on the link in App-header.vue to return

<router-link :to="{name: 'blog}">Blog</router-link>
, but nothing happens, there are no errors in the console. The link is working, it just doesn't work in this case. I can make it in the BlogFeed.vue component to return me to the first page from the pagination, but this is not quite what I need, I need the link from App-header.vue to take me to the root of my blog. Here, in my opinion, the problem is because of the same router'a. Vue.js is not going to go where it already is.
router.js
{
        path: '/', component: Blog, // здесь мой App-header.vue
        children: [
            {path: '/', component: BlogFeed, name: 'blog'}, // здесь мои посты с пагинацией
            {path: '/post/:id/', component: Detail, name: 'post_detail'},
            {path: '/about/', component: About, name: 'about'},
            {path: '/post/category/:id/', component: PostCategories, name: 'post_categories'},
            {path: '/search-result', component: SearchResult, name: 'search_result'},
        ]
    },

Maybe somehow you can reload the component BlogFeed.vue ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-08-11
@google_online

Make the page number a parameter of the route - then there will be no problems moving from anywhere, not only to the first page, but also to any other.
UPD. Let me expand my thoughts a bit. As I understand it, this is a continuation of your previous question .
Component with pagination - when changing the page, instead of setting the current active page, will be executed $router.push, the current page itself from the component property will become its parameter and will be taken from the route parameters. Approximately so . I don’t know if this looks like what you need, if not, throw your code into the sandbox, then maybe I can tell you more precisely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question