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.
Related
On the link below, I have an application with some route problem and I can't figure out why this is happen. I'm using Node.js to configure a http-server.
When I try to access localhost:8080/#home, nothing happens.
However, when I configure a "redirect to", the application open in a link like this: "...:8080/#home!#home"
https://github.com/tvbuosi/AngularJS
angular.module('meuModulo',['ngRoute'])
.config(function($routeProvider){
$routeProvider
.when('/home', {
templateUrl: 'templates/home.html',
controller: 'indexController'
})
.when('/contato', {
templateUrl: 'templates/contato.html'
})
.otherwise({
redirectTo: '/home'
});
});
I have a symfony application which works in a subdirectory:
www.example.com/subdirectory
At this point my application is routed client side with angularjs-framework:
app.config(["$routeProvider", function($routeProvider) {
$routeProvider.
when('/', {
redirectTo: '/homepage'
}).
when('/homepage', {
templateUrl: 'index1.html',
controller: 'HomepageCtrl'
}).
when('/contact', {
templateUrl: 'index2.html',
controller: 'ContactCtrl'
}).
otherwise({
redirectTo: '/homepage'
});
}]);
When the site is loaded:
www.example.com/subdirectory
it automatically changes to:
www.example.com/subdirectory#/homepage
But it should be
www.example.com/subdirectory/#homepage
Anybody could help me to get this working?
Thanks and greetings!
For changing the base URL of your application you could use <base href="/subdirectory/"> inside your head tag of page.
But as per your $routeProvider setting the remaining part of URL seems OK to me. If you really wanted to change it then you need to replace
/homepage
with
homepage
in config phase of angular.
I'm trying to make a routing , it's working when I just clicking on links , but when I refresh the page , browser says not found ! I'm using html5mode , also when I set the # on url and search page manually it just works! what's the problem ?
this is app.js :
app = angular.module("app", [ "ngRoute" ]);
app.config(function($locationProvider, $routeProvider) {
$routeProvider.when("/", {
templateUrl: "partials/index.html",
controller: "mainCtrl"
}).when("/index", {
templateUrl: "partials/index.html"
}).when("/person", {
templateUrl: "partials/person.html",
controller: "personCtrl"
}).when("/person/:id", {
templateUrl: "partials/personShow.html",
controller: "personShowCtrl"
}).when("/about", {
templateUrl: "/partials/about.html"
}).when("/contact", {
templateUrl: "/partials/contact.html"
}).when("/coworking", {
templateUrl: "/partials/coworking.html"
}).otherwise({
redirectTo: "/partials/person.html"
});
$locationProvider.html5Mode(true);
});
Here is excatly same question, anwsered by me:
tl;dr
You need a webserver, like Apache, Nginx or something based on Node.js and you need to redirect all your http calls to index.html
My /home template doesn't have an associated controller (it's blank). Anyway to skip loading the controller and just load the view? I'm using AngularAMD to lazy load so it's an additional call just to get a blank controller file.
app.config(function ($routeProvider) {
$routeProvider
.when('/home', {
templateUrl 'home/home.html',
controller: 'HomeController' //is empty because page is just static text
})
.when('/login', {
templateUrl: 'login/login.html',
controller: 'LoginController'
})
.otherwise({
redirectTo: '/home'
});
});
Nvm, found that you can leave controller: '' blank and it works. It was just throwing an error in my case because I forgot to remove the ng-controller="HomeController" tag from the template/view. Once I removed that, the error was no longer being thrown (in console).
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")
}
});