https://github.com/igorrendulic/appengineangularjsweb
Appengine and AngularJS Reloading angular page using ng-route in html5
https://github.com/igorrendulic/appengineangularjsweb
404 angular appengine ng-route refresh url-rewrite
Last synced: 7 months ago
JSON representation
Appengine and AngularJS Reloading angular page using ng-route in html5
- Host: GitHub
- URL: https://github.com/igorrendulic/appengineangularjsweb
- Owner: igorrendulic
- License: other
- Created: 2017-06-09T17:27:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-29T19:21:33.000Z (almost 7 years ago)
- Last Synced: 2025-01-13T15:51:44.965Z (9 months ago)
- Topics: 404, angular, appengine, ng-route, refresh, url-rewrite
- Language: Shell
- Size: 97.7 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Google Appengine AngularJS Example ng-Route avoid 404 on Refresh
From the [Angular Docs](https://docs.angularjs.org/guide/$location) using `$location` with ng-route can have problems loading pages when refreshing the relative link, e.g. /about.
```
Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html). Requiring a tag is also important for this case, as it allows AngularJS to differentiate between the part of the url that is the application base and the path that should be handled by the application.
```The reason this happens is when you first visit the page (`/about`) the index page wasn't loaded so ng-route has no way of knowing you need to have a `main` page loaded first and route to links from there.
This is a simple example that solves this problem the right way.
The solution is in `main.py` class.
```
class RefreshPageHandler(webapp2.RequestHandler):
def get(self, path):
template_values = {}
template = JINJA_ENVIRONMENT.get_template('app/index.html')
self.response.write(template.render(template_values))APP = webapp2.WSGIApplication([
('/(.*)', RefreshPageHandler),
], debug=True)
```