maciejtreder / ng-toolkit

:star: Angular tool-box! Start your PWA in two steps! Add Serverless support for existing projects and much more
https://www.angular-universal-pwa.maciejtreder.com
MIT License
1.12k stars 157 forks source link

@ng-toolkit/universal window.location is undefined #838

Open rragoomundun opened 3 years ago

rragoomundun commented 3 years ago

I'm submitting a...


[ ] Bug report
[x] Feature request
[ ] Documentation issue or request

In package


[ ] @ng-toolkit/init
[ ] @ng-toolkit/serverless
[x] @ng-toolkit/universal
[ ] @ng-toolkit/pwa
[ ] @ng-toolkit/firebug

Current behavior

window.location is returning undefined during server-side rendering. As I currently understand this is not possible by injecting WINDOW from 'ng-toolkit/universal'. I found a few possible solutions online:

But none of them worked for me.

Expected behavior

I need window.location to return all the usual data when executed in a browser.

Minimal reproduction of the problem with instructions


constructor(@Inject(WINDOW) private window: Window) {
    const { host } = this.window.location;
    console.log(host);
}

Environment


- Angular version: 8.3.8
- Node version: 10.19.0
- Platform:  Ubuntu 20.04