Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to get the URL routing to jump to the correct page/view in angular spa setup

I have an index page setup like:

<html data-ng-app="app">
  <body>
    <div>
      <div data-ng-include="'/app/layout/shell.html'"></div>
    </div>
  </body>
</html>

A shell page like:

<div data-ng-controller="ShellCtrl as vm">
<header>
    <div data-ng-include="'/app/layout/topnav.html'"></div>
</header>
<section id="content" class="content">
    <div data-ng-view></div>
</section>
</div>

And the topnav.html containing a navbar with links pointing to different pages like:

 <ul class="nav navbar-nav"> 
            <li class=""><a href="#/about"><span class="glyphicon glyphicon-info-sign"></span> About</a></li>
        </ul>

Now when I click on the About link, it loads my about page in the content section like it should creating the URL

http://localhost/#/about"

And my routeprovider setup like:

app.config(['$routeProvider', '$locationProvider',
  function ($routeProvider, $locationProvider) {
      //$locationProvider.html5Mode(true);

      $routeProvider.
       when('/', {
           templateUrl: 'app/partials/home.html',
           controller: "HomeCtrl"
       }).
        when('/about', {
            templateUrl: 'app/partials/about.html',
            controller: 'AboutCtrl'
        }).
        when('/contact', {
            templateUrl: 'app/partials/contact.html'
        }).
        otherwise({
            redirectTo: '/'
        });

  }]);

Now I can switch to the pages in my app, but whenever i just throw in the url into a new window to 'bookmark' to the about page, it doesn't work, it doesn't load the about view. In fact, when i just load

http://localhost/  

it doesn't load my home view either at first.

Am I missing a key piece to not get the URL routing to load my views properly from URL?

share|improve this question
    
Not to be all "is the computer plugged in" but did you clear you cache? I ask because I saw the //html5mode. Also what is the default page for "localhost/";? (html, chtml, etc) –  Cory Silva Dec 28 '13 at 8:33
    
Yeah I have tried clearing the cache. My default page is index.html –  cjsmith Dec 28 '13 at 19:06
    
I don't quite understand what's causing my issue, if I include app.run(['$route', function ($route) {}]); this seems to correct things and allow the url routing to do its thing. Is this a requirement on the framework or am I setting things up incorrectly somewhere along the way and I'm band-aiding with the app.run line –  cjsmith Dec 28 '13 at 19:47
add comment

1 Answer 1

remember if you are using Angular Js all your page loads etc are in the index.html page.

If you load the page directly from url it would not load because it requires some javascripts like the route,config etc to have run and these are tied to your index html page.

You can specify a startup page in your Properties window to #.

Hope this answers your question

share|improve this answer
    
Could you improve your answer by adding some example codes? –  mathielo Mar 21 at 21:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.