API: The page transition Property

    • Type: String or Object or Function

    To define a custom transition for a specific route, simply add the transition key to the page component.

    If the transition key is set as a string, it will be used as the transition.name.

    1. export default {
    2. transition: 'test'
    3. }

    Nuxt.js will use these settings to set the component as follows:

    1. export default {
    2. transition: {
    3. name: 'test',
    4. mode: 'out-in'
    5. }

    Nuxt.js will use these settings to set the component as follows:

    The transition object can have the following properties:

    You can also define methods in the page transition property, these are for the JavaScript hooks:

    • beforeEnter(el)
    • enter(el, done)
    • afterEnter(el)
    • enterCancelled(el)
    • beforeLeave(el)
    • leave(el, done)
    • leaveCancelled(el)
    1. export default {
    2. transition: {
    3. afterLeave(el) {
    4. }
    5. }
    6. }

    The default transition mode for pages differs from the default mode in Vue.js. The transition mode is by default set to out-in. If you want to run leaving and entering transitions simultaneously, you have to set the mode to the empty string mode: ''.

    If the transition key is set as a function:

    1. export default {
    2. transition (to, from) {
    3. if (!from) { return 'slide-left' }
    4. return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
    5. }
    6. }

    Transitions applied on navigation:

    • / to /posts => slide-left,
    • /posts to /posts?page=3 => slide-left,
    • /posts?page=3 to /posts?page=2 => .