I work on a pretty old angular project, we started working on it on 2.0 release, and upgraded it release after release. We’re on 4.3 for now
Now, the project is very complex, with a lot of features, and a lot of (old) peer dependencies, not maintained anymore for some of them.
I tried to implement angular universal on this project, to improve SEO, but I come accross errors one after another, and it looks like there’s no end at this.
So my questions are :
- is there a way to implement angular universal on old project, without refactoring everything ?
- if no, is there a way to implement angular universal only on a part of the project, like on statical-non-complex pages ?
All answer and hints are welcome !
2
Answers
Implementing Angular universal on old project can be really, really painful :
I have to implement it on a old project too, and, like you, I had a lot of compilation errors. So I decided to split my app between two parts, two projects :
The bad part is that the 2 projects are independent from each others, so you can’t use things like
localStorage
,routerLink
etc. But they’re connected to the same API, so you can always share data between themTechnically, I did it like this :
app-universal
folder, with theapp-universal.module.ts
<base href="">
of the simplified app to<base href="/content">
angular-cli.json
:package.json
:and running
npm run build-server
to compile your simplified app and render it with universal.Location
andReverseProxy
on my server to launch my main app on the/
path, and my simplified app on/content
or/blog
or/whatever
path :In the /etc/apache2/site-availables/your-project.conf file (on the
<VirtualHost:.80>
block, afterDocumentRoot
for example):And then you can use
pm2
to keep your Node.js application up in the background: How To Set Up a Node.js Application for Production on Ubuntu 16.04And that waq done. I had split my project into two sub-project independent from each-other and run them on the same domain, with all the
/content/*
url SEO friendlyTo help you pass trough current universal errors : Angular with universal does not work
Nowadays there is one command which will make life a lot easier for you:
You can read more about it here:
https://angular.io/guide/universal