Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 无法使Angular html5mode和UrlRewriteFilter使用某些URL大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用带有 @L_675_0@ / jersey REST API的AngularJS 1.3 webapp.我终于让html5mode与 Tuckey UrlRewriteFilter一起使用,这样就像localhost:8080 /#/ page这样的东西现在只是localhost:8080 / page.但是,我似乎无法获得像localhost这样更复杂的东西:8080 / mypage / category / subcategory / item正常工作.在单个浏览器选项卡中,此URL将在html5mode中加载,但如果我在新选项卡中打开该链接,则会获得404.

这是我的pom和web.xml文件

的pom.xml

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filterS.Urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>confPath</param-name>
        <param-value>/WEB-INF/urlrewrite.xml</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>requEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

web.xml中:

<urlrewrite>
    <rule match-type="wildcard">
        <from>*/page</from>
        <to>index.html</to>
    </rule>

    // what should this rule look like in order to recognize a url like:
    // localhost:8080/mypage/category/subcategory/item
    <rule match-type="wildcard">
        <from>?</from>
        <to>index.html</to>
    </rule>
</urlrewrite>

我通读了UrlRewriteFilter文档here并尝试使用通配符匹配和正则表达式语法的不同变体,但我总是得到404.

我还要补充一点,我正在使用angular-ui-router版本0.2.13,我的网页/状态的url看起来像/ mypage /:category /:subcategory /:item.

所以我的问题是如何匹配这种模式,以便重定向到index.html对html5mode正常工作,或者我应该以不同方式配置路由以更好地与UrlRewriteFilter一起使用?

这是我最终使用的
<urlrewrite>
<rule match-type="regex" enabled="true">
    <condition type="request-filename" operator="notfile" />
    <condition type="request-filename" operator="notdir" />
    <condition type="request-uri" operator="notequal">(\.html|\.js)</condition>
    <from>^/html/(.*rootpage1.*|.*rootpage2.*)$</from>
    <to last="true">/html/index.html</to>
</rule>

正如我的应用使用< base href =“/ myapp / html /”>

还必须将index.html上的引用从相对更改为href =“/ myapp / html / otherpage.html”,因为例如.当在/ myapp / html / rootpage1 / page1 / something上使用相对引用时,重写将url传递给index.html,它在rootpage1 / scope上,而不是html / scope.

大佬总结

以上是大佬教程为你收集整理的angularjs – 无法使Angular html5mode和UrlRewriteFilter使用某些URL全部内容,希望文章能够帮你解决angularjs – 无法使Angular html5mode和UrlRewriteFilter使用某些URL所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。