I followed the Angular documentation to built a separate distributable copy of my angular universal app for each locale.
Steps:
define the locales in the build configuration in the angular.json.
set "localize" and "aot" option to true in the build section of
angular.jsonworkspace build configuration file.npm run build:ssrdist/my-app/browser/ |-- fr |-- enmodified the server.ts:
export function app(lang: string): express.Express { const server = express(); const distFolder = join(process.cwd(), 'dist/my-app/browser' + lang); //rest as default } function run(): void { const port = process.env['PORT'] || 4000; const appFr = app('/fr'); const appEn = app('/en'); const server = express(); server.use('/fr', appFr); server.use('/en', appEn); server.use('', appEn); server.listen(port, () => { console.log(`Node Express server listening on http://localhost:${port}`); }); }
Now I can open http://localhost:4200/en for english- and http://localhost:4200/fr for french version in the browser.
How to navigate between both url (languages) within my app.component.ts?
Are there other options than:
if (isPlatformBrowser(this.platformId)) {
window.location.href = url;
}