<tfoot id='yHkXG'></tfoot>

      <i id='yHkXG'><tr id='yHkXG'><dt id='yHkXG'><q id='yHkXG'><span id='yHkXG'><b id='yHkXG'><form id='yHkXG'><ins id='yHkXG'></ins><ul id='yHkXG'></ul><sub id='yHkXG'></sub></form><legend id='yHkXG'></legend><bdo id='yHkXG'><pre id='yHkXG'><center id='yHkXG'></center></pre></bdo></b><th id='yHkXG'></th></span></q></dt></tr></i><div id='yHkXG'><tfoot id='yHkXG'></tfoot><dl id='yHkXG'><fieldset id='yHkXG'></fieldset></dl></div>

      1. <small id='yHkXG'></small><noframes id='yHkXG'>

        <legend id='yHkXG'><style id='yHkXG'><dir id='yHkXG'><q id='yHkXG'></q></dir></style></legend>
          <bdo id='yHkXG'></bdo><ul id='yHkXG'></ul>

        使用启用 Html5 模式的 Angular Ui 路由器时页面重新加载失败

        Page reload fails when using Angular Ui Router with Html5 mode enabled(使用启用 Html5 模式的 Angular Ui 路由器时页面重新加载失败)

        1. <i id='G06XK'><tr id='G06XK'><dt id='G06XK'><q id='G06XK'><span id='G06XK'><b id='G06XK'><form id='G06XK'><ins id='G06XK'></ins><ul id='G06XK'></ul><sub id='G06XK'></sub></form><legend id='G06XK'></legend><bdo id='G06XK'><pre id='G06XK'><center id='G06XK'></center></pre></bdo></b><th id='G06XK'></th></span></q></dt></tr></i><div id='G06XK'><tfoot id='G06XK'></tfoot><dl id='G06XK'><fieldset id='G06XK'></fieldset></dl></div>
            • <bdo id='G06XK'></bdo><ul id='G06XK'></ul>

                <legend id='G06XK'><style id='G06XK'><dir id='G06XK'><q id='G06XK'></q></dir></style></legend>

                    <tbody id='G06XK'></tbody>
                  <tfoot id='G06XK'></tfoot>
                1. <small id='G06XK'></small><noframes id='G06XK'>

                  本文介绍了使用启用 Html5 模式的 Angular Ui 路由器时页面重新加载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在我的 Angular 应用程序中使用 Angular UI 路由器,并且我已启用 HTML5 模式,通过在配置中使用 $locationProvider 来删除 URL 中的 #.

                  I am using Angular UI Router in my angular app and i have enabled HTML5 mode to remove the # form the URL by using $locationProvider in the config.

                  var app = angular.module('openIDC', ['ui.router']);
                  app.config(function($urlRouterProvider, $stateProvider, $locationProvider) {
                  
                      $locationProvider.html5Mode(true);
                  
                      $urlRouterProvider.otherwise('/');
                  
                      $stateProvider
                      .state('home', {
                          url: '/',
                          templateUrl: 'views/home.html',
                          controller: 'HomeController'
                      })
                      .state('login', {
                          url: '/login', 
                          templateUrl: 'views/login.html',
                          controller: 'LoginController'
                      })
                  });
                  

                  我还在 index.html 文件中设置了 <base href="/"/> 标记.路由工作正常,我可以导航到页面并删除 # 但是当我使用浏览器上的重新加载按钮刷新页面时,会出现 404 错误响应.

                  I have also set the <base href="/" /> tag in the index.html file as well. The routing works fine and i can navigate to pages and the # is removed but when i refresh the page using the reload button on the browser there is a 404 error response.

                  为什么会发生这种情况,我该如何解决它并启用 HTML5 模式以获得正确的 URL

                  Why is this happening and how can i fix it and have HTML5 mode enabled to have proper URLs

                  推荐答案

                  Kasun,出现这种情况的原因是因为您试图从您的子路由之一刷新页面(与 ui-router 无关).

                  Kasun, the reason that this is occurring is because you are trying to refresh the page from one of your sub routes (has nothing to do with ui-router).

                  基本上,如果您请求 www.yourdomain.com/,您的服务器设置可能会返回引导您的 Angular 应用程序的 index.html.应用加载后,任何进一步的 url 更改都会考虑 html5Mode 并通过 ui-router 更新您的页面.

                  Basically if you request www.yourdomain.com/ you likely have your server setup to return index.html which bootstraps your angular app. Once the app has loaded, any further url changes take html5Mode into consideration and update your page via ui-router.

                  当您重新加载页面时,角度应用程序不再有效,因为它尚未加载,因此如果您尝试加载子路由(例如:www.yourdomain.com/someotherpage),那么您的服务器不知道如何处理 /someotherpage 并可能返回 404 或其他一些错误.

                  When you reload your page the angular app is no longer valid as it has not loaded yet, so if you are trying to load a sub route (for example: www.yourdomain.com/someotherpage), then your server does not know how to deal with /someotherpage and likely returns 404 or some other error.

                  您需要做的是配置您的服务器,以便为 所有 路由返回您的 Angular 应用程序.我主要使用 node/express,所以我做了类似的事情:

                  What you need to do is configure your server to return your angular app for all routes. I primarily use node/express, so I do something like:

                  app.get('*', function(req, res, next) {
                      // call all routes and return the index.html file here
                  }
                  

                  注意:我通常使用这样的东西作为最终的全部,但是我还包括其他路由,例如请求静态文件、网络爬虫和任何其他需要处理的特定路由.

                  这篇关于使用启用 Html5 模式的 Angular Ui 路由器时页面重新加载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
                  问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
                  Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                  quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                  CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                  Ordinals in words javascript(javascript中的序数)

                          <tbody id='SocHe'></tbody>
                          <bdo id='SocHe'></bdo><ul id='SocHe'></ul>
                          <i id='SocHe'><tr id='SocHe'><dt id='SocHe'><q id='SocHe'><span id='SocHe'><b id='SocHe'><form id='SocHe'><ins id='SocHe'></ins><ul id='SocHe'></ul><sub id='SocHe'></sub></form><legend id='SocHe'></legend><bdo id='SocHe'><pre id='SocHe'><center id='SocHe'></center></pre></bdo></b><th id='SocHe'></th></span></q></dt></tr></i><div id='SocHe'><tfoot id='SocHe'></tfoot><dl id='SocHe'><fieldset id='SocHe'></fieldset></dl></div>

                          <tfoot id='SocHe'></tfoot>
                        • <small id='SocHe'></small><noframes id='SocHe'>

                          • <legend id='SocHe'><style id='SocHe'><dir id='SocHe'><q id='SocHe'></q></dir></style></legend>