繁体   English   中英

如何使用Angularjs在URL内部没有#的单页应用程序?

[英]How to have single page application without # inside the URL using Angularjs?

我正在尝试使用角度js构建单页面应用程序。 但是,当包含模板时,我不希望在URL内部使用 我用过了

 $locationProvider.html5Mode(true) 

app.config(['$routeProvider', '$locationProvider',
  function ($routeProvider, $locationProvider) {
        $routeProvider.
      when('/dashboardnew', {
                templateUrl: './dashboard_tmp',
                controller: 'CategoryCtrl'
            }).
      otherwise({
                redirectTo: '/dashboardnew'
            });
        // use the HTML5 History API
        $locationProvider.html5Mode(true);
    }]);

但重新加载页面时这不起作用。 我该如何解决这个问题? 谢谢

你不能,这是妥协。 html5模式仅在加载角度时才有效,这就是为什么如果重新加载页面或者路径被加入书签,它将无法工作。 坚持#,人们开始习惯看到它们

当然,你可以在角度使用html5模式,并将每个(非api)请求重写到服务器端的角度主页。 angular将获取网址并转到网址

您需要编辑.htaccess文件

RewriteEngine on

# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.php [L]

RewriteRule:index.php或index.html

暂无
暂无

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

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