Nuxt.js: After the page is changed does has a hook in the layout to listen?

Created on 9 Mar 2018  ·  5Comments  ·  Source: nuxt/nuxt.js

Is there a hook in the layouts to listen after each page change?I want to do something after each page loaded and listen in the layouts

This question is available on Nuxt.js community (#c2578)

Most helpful comment

You could use a middleware to execute some function before each page is rendered: https://nuxtjs.org/guide/routing#middleware

Another way would be to watch the $route property in your layout:

// layout/default.vue
export default {
  watch: {
    $route () {
      console.log('route changed', this.$route)
    }
  },
}

All 5 comments

You could use a middleware to execute some function before each page is rendered: https://nuxtjs.org/guide/routing#middleware

Another way would be to watch the $route property in your layout:

// layout/default.vue
export default {
  watch: {
    $route () {
      console.log('route changed', this.$route)
    }
  },
}

I search the same but not when the route change, rather after the page is rendered.
I did not find anything in doc or forum ...
I need this because i need to apply css class according to the current page in order to apply different style.
So i need to apply these class just when the dom is rendered.

Any idea ?

@usb248 you could add some logic to your pages mounted hook to do this.
If you still have this issue, I'd recommend you open another thread as this is unrelated to the original issue.
Closing this now as there was no more follow up by the original poster.

This question has been resolved by @paulgv, see answer.

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazycrazy picture lazycrazy  ·  3Comments

o-alexandrov picture o-alexandrov  ·  3Comments

surmon-china picture surmon-china  ·  3Comments

gary149 picture gary149  ·  3Comments

mikekidder picture mikekidder  ·  3Comments