简体   繁体   English

是否在没有哈希链接的情况下刷新角度页面?

[英]Make angular page refresh without Hash links?

How can I get angular to page refresh without Hash links? 没有哈希链接的情况下,如何获得有角度的页面刷新? On page refresh my angular app would error and not show the page it was just displaying, so I changed the html5Mode to false ( $locationProvider.html5Mode(false).hashPrefix(""); ) and now I can refresh the page. 在页面刷新时,我的角度应用程序将出错并且不显示它仅显示的页面,因此我将html5Mode更改为false$locationProvider.html5Mode(false).hashPrefix(""); ),现在可以刷新页面了。 But I'm also getting the nasty prefix #/ in the link path. 但是我在链接路径中也得到了讨厌的前缀#/

How do I remove # in the url path while at the same time be able to refresh the page? 如何在网址路径中删除#,同时又可以刷新页面?

Explore this thread: $location / switching between html5 and hashbang mode / link rewriting 探索该线程: $ location /在html5和hashbang模式之间切换/链接重写

You need to make sure all your links are absolute relative to index.html and you probably need a server rewrite. 您需要确保所有链接都是相对于index.html绝对链接,并且可能需要重写服务器。

Have you tried setting base in the head section of your html? 您是否尝试过在HTML的头部设置基础?

<!doctype html>
<html>
<head>
    <meta charset="utf-8">  
    <base href="/">
</head>

Server rewrite will work on refresh, try to add middleware in your server. 服务器重写将在刷新时起作用,请尝试在服务器中添加中间件。 Sample grunt configuration id below. 下面的样本grunt配置ID。 check https://github.com/parmod-arora/angular-url-rewrite for nginx and grunt serve rewrite. 检查https://github.com/parmod-arora/angular-url-rewrite进行nginx和grunt服务重写。

middleware: function (connect) {<br>
        var middlewares = [];<br>
        middlewares.push(modRewrite([
          '!/assets|\\.html|\\.js|\\.css|\\woff|\\ttf|\\swf$ /index.html'
        ]));

        middlewares.push(connect.static('.tmp'));
        middlewares.push(connect().use(
          '/bower_components',
          connect.static('./bower_components')
        ));
        middlewares.push(connect.static(appConfig.app));

        //middlewares.push(require('grunt-connect-proxy/lib/utils').proxyRequest);
        return middlewares;
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM