Skip to content
This repository was archived by the owner on Aug 9, 2018. It is now read-only.

Error: location not available yet #41

Open
alexmarch opened this issue Sep 5, 2017 · 3 comments
Open

Error: location not available yet #41

alexmarch opened this issue Sep 5, 2017 · 3 comments

Comments

@alexmarch
Copy link

When angularjs-server bootstrap my app i have next error: location not available yet

@apparentlymart
Copy link
Collaborator

Hi @alexmarch! Sorry for this annoying error.

This is unfortunately one of the ways in which the AngularJS-abstraction leaks due to differences in the request model between the browser and the server. Any JavaScript code running in a browser is always in the context of a particular URL that exists outside of AngularJS, but when running on the server the request URL is passed in as just another AngularJS module and the sequence of events is such that early initialization code (in providers) can run before it's available.

With the current design, it's necessary for an application to be adapted to these constraints. It may be possible to improve on this by using the lower-level API to construct the context in a different way, but I'm not sure.

This library has been used primarily in an application that is tailored to work well within it, so unfortunately there hasn't been a strong incentive to improve the abstraction since it's generally been easier to adapt the application to work within these additional constraints.

@Usama-Tahir
Copy link

so any workaround to cater this problem? @apparentlymart

@apparentlymart
Copy link
Collaborator

The only workaround is to avoid using $location during bootstrapping, and instead wait to do location-sensitive operations after the application has bootstrapped.

Please note that AngularJS-Server is no longer under active development because Angular Universal is likely to be a better solution for new development. It has a similar high-level approach to AngularJS-Server but is first-class.

Additionally, Say Media is now solving this problem a different way (by not using AngularJS to render pages at all) and so AngularJS-Server is no longer running in production there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants