Angular ui router html5Mode false and accented URLs in chrome - angularjs

I always use html5Mode true when using angular ui-router but for a project hosted on github pages, I can't activate this mode given that no server side redirection is possible. So lets go with uggly hashbangs # in URL ;)
My state
.state('app.root.elus', {
url : 'élus',
Displays in Chromium Browser URL bar :
/#/%C3%A9lus
But if I activate html5Mode, the URL displays correctly
/#/élus
In Firefox, in both modes, accents are correctly displayed ...
Would anybody have a beginning of explanation and solution ?

Related

Unable to use with url encoding in html5 mode angularjs

I am using url encoding with angularjs to send data to a view it works perfectly fine but when I make html5 mode using
$locationProvider.html5Mode(true);
I get the following error
Cannot GET /test/adddata/eayGcUzBmcW7XeLhgCCjA0oiQhmuJemjrArCKHPsffYKoVGTwZBIY80ejEfo50m9%7Cdata#domain.com
I am using ui router and the route is /test/adddata/:data.
Note:
I am using lite-server for development purpose.
Edit:
when I tried
/#/test/adddata/eayGcUzBmcW7XeLhgCCjA0oiQhmuJemjrArCKHPsffYKoVGTwZBIY80ejEfo50m9%7Cdata#domain.com
in html5 mode it redirected me to
/test/adddata/eayGcUzBmcW7XeLhgCCjA0oiQhmuJemjrArCKHPsffYKoVGTwZBIY80ejEfo50m9%7Cdata#domain.com
and it is working but curious on why it works is it specific to lite-server

AngularJS redirect to home page after login not working

My application is with spring + angularJS and after authentication from controller i am not able to redirect to home page.
console.log("id:"+employee.id);
alert("Trying to redirect to home page");
$location.path("/home/"+employee.id);
When this gets executed http://localhost:9393/login#/home/21 is being redirected in the url but i want http://localhost:9393/home/21 (without /login#)
This is happening because $location is using Hashbang URL, you can change this by enabling Html5Mode .
enter image description here
So include this in .config method of your module.
locationProvider.html5Mode(true);
For more details look here AngularJS Guide for $location
The hash is because of the hashbang mode. you will have to configure html5 mode. This tutorial explains how to enable html5mode (pretty url)
HTML 5 Mode- angularJs
For more details look here AngularJS Guide for $location

AngularJS html5Mode in IE9 stuck in refresh loop

Our application is having problems when using html5Mode in IE9. I have commented out all our code except the router to ensure it is nothing to do with our code. There are no errors in the console except a warning stating "Document mode restart from Quirks to IE9 standards." We are using version 1.2.0 of AngularJS. It is working perfect in IE10+, Safari, Chrome and Firefox. Changing to html5Mode true fixes the refresh loop.
The problem was our back end controller. It was using logic to redirect, basically removing the # that the Angular router was adding. Angular was then adding the # back hence the refresh loop.
Have you added to declare the html is in html5 ?

AngularJS and PhoneGap: $location.path causes subsequent tempateUrl lookup to fail

I'm having trouble getting path lookup to work with a AngularJS v1.2.0 and PhoneGap/Cordova Android application. I've come pretty far with html5mode(true) by setting <base href="."/> in index.html and then changing $routeProvider.when('/') to $routeProvider.when('/android_asset/www/index.html'). After that I am able to get redirectTo('login') to reach $routeProvider.when('/login') and there render templateUrl: 'static/partials/login.html' as expected.
The problem I have is that if I instead try to redirect to the login page from my Javascript code with $location.path('/login');, the route is found but templateUrl loading fails with an insecurl exception.
I've tried whitelisting access to file:// by using the new angular-sanitize module, but that does not help.
How can I make $location.path() do the same things as redirectTo so that the partial is loaded? Or is there some other way to solve this problem?
UPDATE: I got a bit forward by adding a call to replace() after the path function, e.g.:
$location.path('/login').replace();
but that seems like a hack, and it still causes the templateUrl in the otherwise route to fail with the same exception.
Any ideas on what might be wrong? Is it that html5mode(true) just does not work at this moment with Phonegap and the only way to fix this is to set it to false and add hashtags to every path (like is done in the angular phonegap seed project)?
For future reference, this is how I managed to solve the problem:
AngularJS currently does not seem to support html5mode(true) inside a Cordova application because of the insecurl problem I reported. What I had to do is add
var h5m = (typeof html5Mode !== 'undefined') ? html5Mode : true;
$locationProvider.html5Mode(h5m);
which gives me the possibility to explicitly set html5Mode in the PhoneGap index.html with a global variable:
<script>
var html5Mode = false;
</script>
So now $location.path('/login') as well as redirectTo: 'login' works, but links in html files, don't. To get those working in PhoneGap, with html5Mode disabled, I had to add #/ in front of every link, e.g. login.
That makes PhoneGap work, but breaks the web page which uses History API with html5Mode(true). The last piece of the puzzle was to add <base href="/"/> to the web page's index.html (and leave it out of the index.html of the PhoneGap project.) So now even though I have a link that says #/login in the web page, I get to the url http://example.com/login and don't see any hashes in the address bar.
**
So in the end I have History API working in my web page and History API disabled in the PhoneGap project (where there really is no need for History API as there is no address bar). The only downside is the extra #/ I have to put in each template html file, but that is a minor annoyance compared to the ability to use all of the same html and javascript files for both web and mobile.
I had this same problem as well. I managed to fix it by skipping the leading slash in the route config:
$routeProvider
// route for the foo page
.when('/foo', {
templateUrl: 'foo.html', //previously: '/foo.html'
controller: 'fooController'
}) //etc.

Backbone routes break on refresh with Yeoman

I am building an app with Backbone and Yeoman. I am having an issue with the routing.
I have the following routes set up:
'test' : testMethod,
'' : index
I have set up pushstate:
Backbone.history.start({pushState: true});
I am using Chrome
If enter myApp.com#test the url changes to myApp.com/test and testMethod() fires correctly.
However if I try goto myApp.com/test directly or refresh after the browser has changed the url from # to / then I get a 404.
I am using the Yeoman built in server to test the pages. Could this be causing the issue?
I am not sure if you are using BBB within Yeoman. If you are, this should not be an issue. If you are not using BBB, this is a known issue. BBB has it's rewrite rules setup correctly to use pushstate, but yeoman's built in server does not seem to adopt this. You could edit your grunt.js file with your own rewrite rules to get pushstate working correctly. Some of the users in the above mentioned link have done this successfully.
When your app goes live, you will either need to serve those urls through your server or edit your rewrite rules to do the same. If the latter, and your application relies on SEO, SEO will suffer greatly.

Resources