skip to Main Content

There is a requirement of SEO optimization in nuxt.js project. It requires every route inside the project need add a trailing slash. How to solve the problem?

By the way, there is a question about it, but the accepted answer is not right for me. the question link is here:

2

Answers


  1. Hi 🙂 You need install @nuxtjs/redirect-module and add below rule to nuxt.config.js.

    redirect: [
        {
            from: '^.*(?<!/)$',
            to: (from, req) => req.url + '/'
        }
    ]
    

    My answer is based on antonku’s answer.

    Login or Signup to reply.
  2. The answer from @kanapka94 is correct but incomplete. You need to add the module to your modules attribute in your nuxt configuration, e.g:

    modules: [
        '@nuxtjs/redirect-module',
    ]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search