angularjs - How do I mix links that trigger page refreshes, with Angular's html5Mode = true without breaking the back button? -


i'll walk through problematic flow...

  • i load google.com (just starting point)
  • i goto app.com
  • i nav app.com/projects
  • i nav app.com/api/test (through window.location)
  • i see raw json (good far...)
  • i press back, url changes app.com/projects still see json.
  • i press again, url changes app.com still see json.
  • i press again, google.com loads.
  • i press forward, app.com loads fine... normal

what's odd, i've observed when html5mode = true in webkit—firefox works desired...

. . .

first, server.coffee looks this:

app.get '/partials/:partial', routes.partials app.get '/api/test', api.test app.get '*', routes.index 

basically, requests load index (which bootstraps angular), exception view/partial handler, , test api route responds raw json.

. . .

(i'm using ui-router module managing nested views , ui states; uses $urlrouterprovider, similar angular's $routeprovider)

second, app.coffee looks this:

app = angular.module('app', ['ui-router']) .config([     '$stateprovider'     '$locationprovider'     '$urlrouterprovider'     ($stateprovider, $locationprovider, $urlrouterprovider)->         $urlrouterprovider             .when('/api/test', [                 '$window'                 '$location'                 ($window, $location)->                     $window.location.href = '/api/test'             ])             .otherwise('/')         $stateprovider             .state 'home',                 url: '/'                 templateurl: 'partials/index'                 controller: 'indexctrl'             .state 'projects',                 url: '/projects'                 templateurl: 'partials/projects'                 controller: 'projectsctrl'         $locationprovider.html5mode(true).hashprefix '!' ]) 

since async, had use $window access window.location.href trigger page refresh server handle route.

so question, can mix links trigger page refreshes angular's html5mode without breaking button? webkit bug, and/or there better way this?

ideally, i'd have application running off angular—but things "about" or "contact" page (which have no need dynamic or async), served directly server using regular page refreshes...

help!

two options:

  1. if you're using <a /> tags, specify target="_self" let angularjs know shouldn't capture clicks (those links handled browser normally). not hack; normal documented behavior.
  2. use $window.location = 'foo' have been doing. acceptable.

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -