angularjs ui-router strange behaviour with additional segment in route

Not fully sure where is theissue here… but I created working plunker, which should help to see what is needed to see the HTML 5 and ui-router working together. In case that server side is configured properly, this should work out of the box. Please, check this firstly:

Now, this would be adjusted state def, to show the deep url nesting:

$stateProvider
    .state('roles', {
        url: '/roles/:id',
        ...
    })
    .state('roles.logs', {
        url: '/logs',
        ...
    })
    .state('roles.logs.parameters', {
        url: '/parameters',
        ...
    });

To make all these call below wroking:

<nav> 
  <a href="https://stackoverflow.com/questions/25999262/roles/11">roles/11/</a><br />
  <a href="roles/22/logs">roles/22/logs</a><br />
  <a href="roles/33/logs/parameters">roles/33/logs/parameters</a><br />
</nav>

<nav> 
  <a ui-sref="roles({id:1})">roles </a><br />
  <a ui-sref="roles.logs({id:2})">roles.logs</a><br />
  <a ui-sref="roles.logs.parameters({id:3})">roles.logs.parameters</a><br />
</nav>

we have to not forget to properly set the base url, in our example:

<!DOCTYPE html>
<html ng-app="MyApp">

  <head>
    ...
    <base href="https://stackoverflow.com/cTRk4o9HRELCQ4OK/" />

But for plunker we should set that dynamically:

<script>
  document.write('<base href="'+ document.location.pathname +'" />')
</script>

Check working example here

Leave a Comment