igorrendulic / AppengineAngularJSWeb

Appengine and AngularJS Reloading angular page using ng-route in html5

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Appengine AngularJS Example ng-Route avoid 404 on Refresh

From the Angular Docs 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 <base> 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)

About

Appengine and AngularJS Reloading angular page using ng-route in html5

License:Other


Languages

Language:Shell 35.0%Language:HTML 28.1%Language:JavaScript 24.5%Language:Python 11.6%Language:CSS 0.8%