Routing didn't work on SSR
See original GitHub issue- I’m submitting a …
- [ ] bug report
-
What modules are related to this Issue?
-
Do you want to request a feature or report a bug? A bug
-
What is the current behavior? The routing part didn’t work on SSR by typing directly in the browser the path or click on
a
tag to open a new link. By example: The first entry route is:user
, insideuser
click to change the route toproducts
works normally. Fromproducts
go toproducts/:id
works perfectly. But if I type in directly in the address bar the url by example:localhost:4200/products/1
it will never find out where is the route and turn out 504 error Gateway time out.
The routing part work normally before.
-
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo. I will try to reproduce with a clone from
universal-starter
later -
What is the expected behavior? Routing works normally
-
What is the motivation / use case for changing the behavior? The routing works before should also work for SSR
-
Please tell us about your environment:
- Angular version: 5.2.5
- Browser: all
- Language: Typescript 2.6.2
- OS: Window
- Platform: NodeJS
- Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:11 (1 by maintainers)
this.router.url is available in SSR in Angular11? the below code is not executing the Server side let routeName = ‘home’; if(this.isBrowser) { $(‘head’).find(‘script[type=“application/ld+json”]’).remove(); } if (this.router && this.router.url && this.router.url !== ‘/’) { if (this.router.url && this.router.url.indexOf(‘?’)) { routeName = this.router.url.split(‘?’)[0]; } else { routeName = this.router.url; } if (routeName && routeName.includes(‘/car-rental/’)) { routeName = routeName.replace(‘/car-rental/’, ‘’); routeName = routeName.replace(‘-car-rental’, ‘’); } if (routeName && routeName.includes(‘-one-way-car-rental’)) { routeName = routeName.replace(‘-one-way-car-rental’, ‘’); routeName = routeName.replace(‘/car-rental/’, ‘’); } } const script = document.createElement(‘script’); script.setAttribute(‘type’, ‘application/ld+json’); script.async = true; script.src = ‘assets/data/’ + routeName +‘-schema.js’; document.head.appendChild(script);
Are there any new suggestions? Still have the same problem…