问题
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:
- User go to
domain.com/:id
- Check
title
forid
from url inside angular app - 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