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 ?
相关问题
- Axios OPTIONS instead of POST Request. Express Res
- Vue.js - set slot content programmatically
- Getting Uncaught TypeError: …default is not a cons
- Vue.js computed property loses its reactivity when
- How to remove the Vuetify append-icon from the seq
相关文章
- Best way to dynamically change theme of my Vue.js
- vue-router how to persist navbar?
- How to Properly Use Vue Router beforeRouteEnter or
- Difference between nameFunction() {} and nameFunct
- Vue - best way to reuse methods
- setTimeout() not working called from vueJS method
- How to unbind an array copy in Vue.js
- Vue Cli 3 Local fonts not loading
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.
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.