ngrx / platform

Reactive State for Angular
https://ngrx.io
Other
8.01k stars 1.97k forks source link

no store to brower. #1413

Closed erdongritian closed 5 years ago

erdongritian commented 5 years ago

when i use ng build ,and put dist to tomcat ,it can find local storage in brower,but when i use ng build -prod,and put dist to tomcat,and then login ,there is no local storage,why? from package.json:

`   "@angular-devkit/core": "^0.5.7",
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "@ngrx/effects": "^5.2.0",
    "@ngrx/entity": "^5.2.0",
    "@ngrx/router-store": "^5.2.0",
    "@ngrx/schematics": "^5.2.0",
    "@ngrx/store": "^5.2.0",
    "@ngx-translate/core": "^9.1.1",
    "@ngx-translate/http-loader": "^2.0.1",
    "core-js": "^2.4.1",
    "echarts": "^4.0.4",
    "file-saver": "^2.0.0-rc.4",
    "ng-zorro-antd": "^0.7.1",
    "ngrx-store-freeze": "^0.2.1",
    "ngrx-store-localstorage": "^5.1.0",
    "ngx-cookie-service": "^1.0.10",
    "ngx-echarts": "^2.1.0",
    "ngx-filesaver": "^2.1.1",
    "node-sass": "^4.9.3",
    "rxjs": "^5.5.2",
    "xlsx": "^0.14.0",
    "zone.js": "^0.8.14",
    "@ngrx/store-devtools": "^5.2.0"
 `

and some code:

checkAuth(): Observable {
    return this.store$
      .select(s => s.auth.auth)
      .pipe(
        map(auth => {
          console.log(auth);
          const result = auth && auth.token !== undefined && auth.token !== null;

          if (!result) {
            this.router.navigate(['/login']);
          }
          return result;
        }),
        defaultIfEmpty(false)
      );
  }

when i use ng build -prod, after login,click other link,it is work, above code 'auth' is not null,but localstory is nothing. when i press F5 or refresh,the above code auth is null ,where is wrong. but when i ues ng build, not prod,it is work.and have localstory.

timdeschryver commented 5 years ago

Support questions should be asked on stackoverflow (with a ngrx tag) or the gitter channel.

I'm not sure if this is NgRx "its problem". From the code snippets provided I also don't see something of localStorage. You could check if the environment config is correct for a prod build.