0

I'm trying to access a nested view with the direct url, without navigating through links but it's not working.

My config is:

myApp.config(function ($stateProvider, $locationProvider) {
    $stateProvider
        .state('st1', {
            url: '/st1',
            templateUrl: 'st1.html',
        })
        .state('st1.st2', {
            url: '/st2',
            templateUrl: 'st2.html',
        })
    ;
    $locationProvider.html5Mode(true);
});

st1.html:

<h1>ST1</h1>

<div ui-view></div>

<a ui-sref="st1.st2">ST2</a>

st2.html:

<h2>ST2</h2>

<a ui-sref="st1">ST1</a>

I go directly to /st1, typing it not clicking a link, st1 html shows up.

When I click the link in st1, the location path changes to /st1/st2 and st2's content shows up, that is what I want, but when I refresh on /st1/st2 the page is empty.

What do I miss?

indriq
  • 372
  • 1
  • 4
  • 10
  • 1
    That would be almost for sure your server configuration. Carefully check the FAQ https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode – Radim Köhler Dec 14 '14 at 12:12
  • The index.html is loading but the views' aren't. – indriq Dec 14 '14 at 12:37
  • It's working with hashbang so yea my server conf must be the problem, but it seems to be good: `root 'application#index'` `get '*path' => 'application#index'` – indriq Dec 14 '14 at 13:47
  • 1
    This issue is for sure about the server setting. Check carefully the FAQ I gave you. If server is set properly, all will start to work. Here is [working example](http://stackoverflow.com/a/26009350/1679310) – Radim Köhler Dec 14 '14 at 16:10
  • Gosh.. it was my fault. I always forget not to learn new things before the 3rd coffee... thanks for the help, it works now. – indriq Dec 14 '14 at 16:47
  • Great to see that sir, UI-Router is awesome lib... ;) – Radim Köhler Dec 14 '14 at 16:48
  • Indeed. It should be angular's official router. :) – indriq Dec 15 '14 at 12:07

0 Answers0