Is it possible to add redirect (301) inside angular app?

荒凉一梦 提交于 2021-01-29 12:58:14

问题


Let's say my app is running on domain.com and most of links in the internet to this site looks like this: domain.com/:id.

I want to improve SEO a little bit and add redirects (301): domain.com/:id => domain.com/:title. But to get title for id I have to run angular app and check this in DB.

So what I want to do is:

  1. User go to domain.com/:id
  2. Check title for id from url inside angular app
  3. Redirect user with 301 status to domain.com/:title

回答1:


You have to run Angular using Angular Universal with server-side rendering. There is a guide to get you started, and if it's a new Angular project it's relatively easy to add.

https://angular.io/guide/universal

You then have to tell Express to perform a 301 redirect, and this can be done by configuring the main module used for SSR.

https://gist.github.com/KostyaEsmukov/ce8a6486b2ea596c138770ae393b196f



来源:https://stackoverflow.com/questions/55653406/is-it-possible-to-add-redirect-301-inside-angular-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!