I am trying to redirect the url using the $routeprovider
$routeProvider.when('/', {
templateUrl : 'scripts/login/login.tpl.html',
controller : 'LoginCtrl'
});
$routeProvider. when('/sample', {
templateUrl: 'sample.html'
});
$routeProvider.otherwise({
redirectTo : '404.html'
});
Below is the url which loads the application
http://localhost:8080/orion-web/app/
when I try to append the word 'sample' to the url
ie
http://localhost:8080/orion-web/app/sample
I get 404 error , This is not the 404.html from the $routeprovider. It's tomcats 404 resource not found page
Do you have a base url set for your page?
It should be <base href="/orion-web/app/"> within the header section of your index.html
In the second $routeprovider.when try removing /
$routeProvider. when('sample', {
templateUrl: 'sample.html'
});
$routeProvider
.when('/', {
templateUrl : 'scripts/login/login.tpl.html',
controller : 'LoginCtrl'
})
. when('/sample', {
templateUrl: 'sample.html'
})
.otherwise({
templateUrl: '404.html'
});
Use this code
Related
i'm having trouble configuring my routers.
the router going to /:lang/:country & /:lang/:country/:city are not working. 1st three routes works OK, how cna I fix it?
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', { // works
templateUrl : 'templates/main.html',
controller: 'MainCtrl'
}).when('/:lang', { // works
templateUrl : 'templates/main.html',
controller: 'MainCtrl'
}).when('/:lang/premium-benefits', { // works
templateUrl : 'templates/premium_benefits.html',
controller: 'PremiumBenefitsCtrl'
}).when('/:lang/:country', { // NOT working
templateURL : 'templates/destination.html',
controller: 'DestinationCtrl'
}).when('/:lang/:country/:city', { // NOT working
templateURL : 'templates/destination.html',
controller: 'DestinationCtrl'
}).otherwise({
templateURL : 'main.html'
});
$locationProvider.html5Mode({enabled: true, requireBase: true});
}]);
sorry guys, templateURL must be templateUrl lol
When user go to either localhost:8888 or localhost:8888/, my angular application change to url to http://localhost:8888/#!/
This is my angular app in home page:
app.config(['$locationProvider', '$routeProvider',
function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider
.when('/', {
redirectTo: ((window.status === 'signup') ? '/signup' : '/signin')
})
.when("/signin", {
templateUrl: "/public/user/signin.html",
controller: "signinController"
})
.when('/signup', {
templateUrl: "/public/user/signup.html",
controller: "signupController"
})
.otherwise({
redirectTo: '/'
});
}
])
if user go to http://localhost:8888/auth, angular redirects to http://localhost:8888/auth#!/signin,
only if user go to http://localhost:8888/auth/, angular redirects to http://localhost:8888/auth/#!/signin
app.config(['$locationProvider', '$routeProvider',
function($locationProvider, $routeProvider) {
$locationProvider.hashPrefix('!');
$routeProvider
.when('/', {
redirectTo: ((window.status === 'signup') ? '/signup' : '/signin')
})
.when("/signin", {
templateUrl: "/public/user/signin.html",
controller: "signinController"
})
.when('/signup', {
templateUrl: "/public/user/signup.html",
controller: "signupController"
})
.otherwise({
redirectTo: '/'
});
}
])
the angular official website and most of the books recommend using xxx/#!/xxx format. How can I do that?
Edit: I understand that I can add the trailing slash from the server side. but user can directly type xxx.com/auth.
Why is xxx.com working but not xxx.com/auth?
Edit2: the tutorial sample project works for all urls. we have pretty much the same implementation
http://angular.github.io/angular-phonecat/step-8/app/#/phones
try to enter http://angular.github.io/angular-phonecat/step-8/app (without the trailing slash
Tutorial link: https://docs.angularjs.org/tutorial/step_07
This is something you should fix on your back-end by adding a 301 redirect from /auth to /auth/.
Nginx:
rewrite ^/auth$ /auth/ permanent;
Apache:
Redirect "/auth" "/auth/" [R=301]
I have 2 urls /dev and /app. My angular routes is as follows
$routeProvider.
when('/home', {
templateUrl: 'homeTemp',
controller: 'homeCtrl',
}).
when('/home/:pageId', {
templateUrl: 'homeTemp',
controller: 'homeCtrl'
}).
when('/apps', {
templateUrl: 'devTemp',
controller: 'devCtrl',
}).
when('/app/:appId', {
templateUrl: 'devAppTemp',
controller: 'devCtrl'
}).
otherwise({
redirectTo: '/home'
});
Now when my url is /dev#/apps it loads the dev controller and when it's /apps#/home it loads the home controller
What change do I need to add in my routes so that when the url is just /dev it loads the dev controller
Currently because of the otherwise it redirects to /dev#/home
You could create a root level controller that just checks the url and redirects you as needed.
In your $routeProvider add
when('/', {
controller: 'isDevCtrl',
template:""
})
Then in isDevCtrl look at the url and redirect accordingly
yourApp.controller("isDevCtrl", function($location){
if($location.path() == '/dev'){
$location.path("/apps")
}else{
$location.path("/home")
}
});
FOr my angular application , I want to use $locationProvider.html5Mode(true) to remove '#' sign from URL.
I also used but it is not working.
My index.html include "" in header section.
My app.js is as follows.
$routeProvider
.when('/signIn', {
controller: 'signInController',
templateUrl: 'html/views/sign-in.html'
})
.when('/login', {
controller: 'LoginController',
templateUrl: 'html/views/log-in.html'
})
.otherwise({ redirectTo: '/login' });
$locationProvider.html5Mode(true);
All my code (html and scripts) is under App directory. But when I am trying to run my login page is not getting loaded.
Im using angularJS to set where i want the page to go after i login, but if i only have this
function routeProviderFunction($routeProvider){
$routeProvider.when('/default',{
templateUrl: 'HTML/login.html',
controller: funct2
});
$routeProvider.otherwise({
redirectTo: '/default'
});
}
My route provider works in the above code, but after i turn it into this
function routeProviderFunction($routeProvider){
$routeProvider.when('/default',{
templateUrl: 'HTML/login.html',
controller: funct2
});
$routeProvider.when('/adminMenu/:username', {
templateUrl: 'HTML/adminMenu.html',
controller: adminMenu
});
$routeProvider.otherwise({
redirectTo: '/default'
});
}
My route provider ceases to work at all. Any ideas
try to do like this:
$routeProvider
.when('/default', {
templateUrl: 'HTML/login.html',
controller : 'funct2'
}).when('/adminMenu/:username', {
templateUrl: 'HTML/adminMenu.html',
controller : 'adminMenu'
}).otherwise({
redirectTo : '/default'
});
Does the controller adminMenu exist in the global namespace? Press F12 and check the error console. Angular has quite decent error messages. Also worth noting that 'when' is chainable so you should be doing something like this route.when().when().otherwise();
After looking #fabuloso answer, it clicked to me what I needed to fix my problem.
I had
pageApp.config(function($routeProvider) {
$routeProvider
// route for the home page
.when('/', {
templateUrl : 'content/home.html',
controller : 'homeController'
})
// route for the directions page
.when('/directions', {
templateUrl : 'content/directions.html',
controller : 'directionsController'
})
// route for the giftCards page
.when('/giftCards', {
templateUrl : 'content/giftCards.html',
controller : 'giftCardsController'
});
// route for the giftCards page
.when('/contactUs', {
templateUrl : 'content/contactUs.html',
controller : 'contactUsController'
});
});
when adding the last "contactUs" part, I noticed I had a semicolon after the giftCards route, which blows up everything.