加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS Ui-Router嵌套视图不能与html5mode一起使用

发布时间:2020-12-17 16:56:31 所属栏目:安全 来源:网络整理
导读:我正在使用AngularJS和ui-router,我在使用 Html5Mode时遇到了嵌套视图的问题.这个问题只发生在html5上,如果我没有使用它,一切正常.我尝试使用base base href =“/”但没有奏效. 此外,问题只发生在嵌套视图中,在主ui视图上没问题. 这是我正在使用的代码: 的i
我正在使用AngularJS和ui-router,我在使用 Html5Mode时遇到了嵌套视图的问题.这个问题只发生在html5上,如果我没有使用它,一切正常.我尝试使用base< base href =“/”>但没有奏效.

此外,问题只发生在嵌套视图中,在主ui视图上没问题.

这是我正在使用的代码:

的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>

儿童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'
})

如果我使用html5 WITH`,我可以导航,但是当我刷新页面时,我会收到这样的错误:

资源解释为样式表,但使用MIME类型text / html进行传输

如果我使用WITHOUT< base href =“/”/>然后它根本不起作用.但同样,只有孩子的ui-view,父视图仍在工作.

解决方法

直到现在我还没有遇到这样的问题,所以我的知识有限,但我听到了一些可以帮助你的事情.正如 this ui.router tutorial所说:

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.

我希望这有帮助!干杯.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读