Join the Stack Overflow Community
Stack Overflow is a community of 6.2 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I'm using AngularJS with ui-router and I have a problem with nested views while using Html5Mode. This problem only happens with html5, if I'm not using it, everything works fine. I tried to work with base <base href="/"> but didn't work as well.

Also, the problem only happens within nested views, on the main ui-view it's ok.

This is the code I'm using:

index.html

<div>
    <ul>
        <li ui-sref="menu">Menu</li>
        <li ui-sref="user">User</li>
        <li ui-sref="contact">Contact</li>
    </ul>
    <div ui-view autoscroll="false"></div>
</div>

child template.html

<div class="container">
    <div>
        <ul>
            <li ui-sref="user.data">My Info</li>
            <li ui-sref="user.order">My Order</li>
            <li ui-sref="user.budget">My Budget</li>
        </ul>
    </div>
    <div ui-view></div>
</div>

app.js

.state("user", {
    url: "/User",
    templateUrl: "content/user.html",
    controller: "UserCtrl"
})
.state('user.data', {
    url:"/MyData",
    templateUrl: "content/user/user_data.html",
    controller: 'UserCtrl'
})

If I use the html5 WITH `, i can navigate, but when i refresh the page, I get errors like this:

Resource interpreted as Stylesheet but transferred with MIME type text/html

And if I use WITHOUT <base href="/" /> then it doesn't work at all. But again, only for the child ui-view, the parent view is still working.

share|improve this question

I haven't got such problem until now, so my knowledge is limiting, but i've heard a few things that can help you. As this ui.router tutorial says:

HTML5 Mode

The UI Router framework gives you ultimate control over the URLs generated for your site by allowing you to enable HTML5 mode. When enabled, this mode does not generate hash (#) locations, but uses the HTML5 history API to generate clean URLs. The only caveat to this approach is that you must build your application to work under each generated path, rather than just at the root, which is customary in most single-page applications.

I hope this helps! Cheers.

share|improve this answer
    
Yeah, but what I don't understand is because it works for the parent element, but when I reload on a child state, it doesn't work anymore. – CelsomTrindade Aug 14 '15 at 16:22
    
In another discussion on github someone who had the same issue like you, got it fixed with adding a leading / to the child states. – Szkíta Aug 15 '15 at 9:11
    
I tried those things, but none of them worked for me. Maybe it's because of the re-write property on the server-side, I'll try to take a better look at it. – CelsomTrindade Aug 16 '15 at 14:18

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.