0

I want to remove the # on angularjs url. So I followed this blog.

This is my .config() :

.config(['$stateProvider', '$locationProvider' function($stateProvider, $locationProvider,) {

     $stateProvider.state('main', {
        url: '/',
        templateUrl: 'path/to/main.html',
        controller:'mainCtrl'
     })

     $locationProvider.html5Mode(true);
}])

And this is my <header> :

<head>
    <scripts>....

    <base href="/"> // I ADDED THIS
</head>

But when I access the / link. Like this http://localhost/my-app/ it only shows a blank page. There are no error/s on the console so Im assuming that the problem is on the loading of the template. Im using ui.router. Someone encountered this problem? Thanks.

jofftiquez
  • 7,548
  • 10
  • 67
  • 121
  • ng-click(go())) and in go $state.go('somewhere') works? – stackg91 Sep 01 '15 at 09:29
  • I don't need any click events, I want this to happen on load of the web app/. @stackg91 – jofftiquez Sep 01 '15 at 09:32
  • sry I dont really understand what you need that base for can u describe your scenario more If i understand correctly you want to show smth when you access / right? I am just using $urlRouterProvider.otherwise('/login'); so everthing which is not defined by state ends up on login – stackg91 Sep 01 '15 at 09:38

1 Answers1

4

1st When you use <base href="/"> yu set ALL relative URLs appends to that path. So IF your app is aviable at /my-app/ use <base href="/my-app/"> Also you can try relative base href <base href="./">, but i don't recomend it. Now your app is in http://localhost/my-app/ but base is http://localhost/

2nd When you use html5 routing, you may ensure that webserver does not repsonse other page, but your index.html

3rd, after that check your JS, maybe cant load template because of base url...

Community
  • 1
  • 1
ubombi
  • 1,115
  • 2
  • 15
  • 30