-
Notifications
You must be signed in to change notification settings - Fork 756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browser get re-directed automatically in Angular.js App #68
Comments
It looks like the Angular team made a decision to remove the BrowserSync ignores Ajax calls that have this header automatically - but when angular requests a view, something like You have a couple of solutions right now - you can either disable link synchronization or configure your angular app to send the header mentioned above. Disable link synchronization gulp.task('bs', function() {
browserSync.init(['build/index.html', 'build/templates/*.html', 'build/css/*css', 'build/js/*.js'], {
proxy: {
host: '127.0.0.1',
port: '9000'
},
ghostMode: {
links: false
}
});
}); Enable X-Requested-With header myModule.config(function($httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
}); You can read the thread about the decision to remove it here: angular/angular.js#1004 Also, always ensure you're on the latest version of BrowserSync too. |
For any other Angular users out there, here's an example showing how you'd enable the header mentioned above. 'use strict';
angular.module('yourApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute'
])
.config(function ($routeProvider, $httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
}); |
Hi, This has solved the re-direction issue. Thanks... All my anchor tags are working but the click listeners set in JavaScript are not propagated in other devices. Also in my form, I've kept few fields as "required" so once I enter the details in one of the devices, the other device shows "This field is required" and because of which the form is not submitted. Any ideas ? |
The form synchronisation with angular apps is getting some attention soon. It's a WIP as mentioned here #60 |
Any ways this issue is fixed... All the best and I can see Browser Sync as a huge success in coming days... Best of luck 👍 |
Thanks :) |
Sorry for the wrong commit message. My last commit tries to fix #64 instead. |
Actually, that's not entirely true. If I use this:
My route provider doesn't do any routing. I'm still also getting the 'redirect to raw view file' behavior also. Maybe I'm assuming everyone else is using |
Actually, it's gotten worse. Any |
That's ok. I can work with that. Thanks Shane. |
Hi, I've got the same issue. But for me your solution doesn't work at all. Or maybe I'm doing it wrong? var app = angular.module('app',[
'ngRoute',
'app.controllers',
'app.directives',
]);
app.config(['$routeProvider','$httpProvider',
function($routeProvider, $httpProvider) {
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$routeProvider.
when('/courses', {
templateUrl: 'public/partials/courses.html',
controller: 'appCtrl'
}).
when('/course/:courseId', {
templateUrl: 'public/partials/course.html',
controller: 'appCtrl'
}).
when('/course/:courseId/:subjectId/:lessonId', {
templateUrl: 'public/partials/player.html',
controller: 'appCtrl'
}).
when('/course', {
redirectTo: '/courses'
}).
when('/', {
templateUrl: '/public/partials/index.html',
controller: 'appCtrl'
}).
otherwise({
redirectTo: '/'
});
}]);
|
@skorano - are you running the latest version of BrowserSync? |
2.5.2 |
I suppose so.. But i don't know how to check it :) |
|
Ok, problem exist only on Mixture, on any other host server there is no problem with this. So for me is the end of an issue :) |
@shakyShane I'm running into this problem and I've already tried everything recommended here. I've set |
As @kevinSuttle has mentioned, setting |
The Gulp task is
This task fires up the browser initially with the correct URL i.e.
http://192.168.42.242:3002/#/login
but it automatically redirects tohttp://192.168.42.242:3002/templates/login.html
My routes in Angular.js are defined as
I cannot understand why there is a browser re-direct ? Or is it that I'm doing something wrong. Thanks :)
The text was updated successfully, but these errors were encountered: