angular js spring mvc ui-router 路由冲突

前端之家收集整理的这篇文章主要介绍了angular js spring mvc ui-router 路由冲突前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参考了别人的例子,刷新是个特例。 在使用angular ui router 以后,界面浏览器会重定向,当使用F5刷新之后,界面没有走angualr的路由,而是请求服务器,所以服务器后台 web.xml 配置url mapping,以/ang/*请求的就 跳转到默认界面。 $urlRouterProvider.otherwise('home'); $stateProvider .state("home",{ url:"/ang/home",templateUrl: "index.html" }) .state("login",{ url:"/ang/login",templateUrl: "views/login.html" }) <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/springMVC.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping> <!-- 当用户输入刷新空界面的时候跳转到默认界面(F5刷新 浏览器定向请求服务器) --> <servlet> <servlet-name>angularRedirect</servlet-name> <servlet-class>com.hr.angular.AngularRedirect</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>angularRedirect</servlet-name> <url-pattern>/ang/*</url-pattern> </servlet-mapping> protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws ServletException,IOException { String requestUrl = req.getRequestURI(); log.info("angular 后台重新进入首页 请求: " +requestUrl); resp.sendRedirect("/hrmis/Main.html"); } <nav class="navbar navbar-inverse" role="navigation"> <div ng-controller="loginCtrl" > <ul class="nav navbar-nav"> <li ui-sref ="home" class="active" ><a href="">首页</a></li> <li ui-sref = "login" ><a href=""><span>登陆</span> <span></span></a></li> <li ui-sref = "register" ><a href="">注册</a></li> <li ui-sref = "loginOut" ><a href="">退出</a></li> </ul> </div> </nav> <div class="container"> <div ui-view=""></div> </div> 原文链接:https://www.f2er.com/angularjs/148224.html

猜你在找的Angularjs相关文章