For a purpose of SEO i’ve been asked to add a slash at the end of every routes of my nuxt project. For example myapp.com/company should be myapp.com/company/ Is there a clean way to do that in Nuxt ?
For a purpose of SEO i’ve been asked to add a slash at the end of every routes of my nuxt project. For example myapp.com/company should be myapp.com/company/ Is there a clean way to do that in Nuxt ?
3
Answers
ok i found the solution by writting a redirection in a middleware on serverside, so first i added to nuxt.config.js this :
then i created this file /servermiddleware/seo.js :
and finally i write the redirections i want in 301.json in the root folder:
edit: a problem stay here because inside the code of the app links stays without slash so the indexation of robot will use it.... i need to find a better solution.
I am doing the requirement, too. I do the task with the following method, which I do not know it is right.
Two steps:
Nginx rewrite the url, that is to add slash of ‘/’ to the end of url, which the url isn’t ended with a slash. In this case, the http request is sent to the web server.
At another case, if the request (or link routing) is routed at the front end, that the request does not send http request to the web server. Then add a middleware file called addSlash.js like this:
With two steps above, get the task done.
You can set trailingSlash to true in nuxt.config.js like below:
For sitemap:
Details more on https://dev.to/mornir/nuxt-netlify-and-the-trailing-slash-3gge