2016-10-22 39 views
2

取下laravel角度包括hashtag我有一个像使用的.htaccess

<ifModule mod_rewrite.c> 
RewriteEngine on 

# allow social media crawlers to work by redirecting them to a server-rendered static version on the page 

RewriteCond %{HTTP_USER_AGENT} (facebookexternalhit/[0-9]|Twitterbot|Pinterest|Google.*snippet) 
RewriteRule eventApp/(\d*)$ [P] 


# Required to allow direct-linking of pages so they can be processed by Angular 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^(.*) /eventApp/index.html [NC,L] 

</ifModule> 

笨.htaccess文件,但我想从laravel删除#标签。

回答

0

要删除URL片段中的哈希,您只需要设置角度以不添加它,不需要修改.htaccess文件。因此,这个答案提出了一个更清晰的解决方案来解决所提出的问题

在您的角度基本模块中,通常在您定义路线的地方。

angular.module('app', []) 
    .config([ 
     '$routeProvider', 
     '$locationProvider', 
     function($routeProvider, $locationProvider) { 
      // Hashtags no longer appear with this 
      $locationProvider.html5Mode(true); 

      // Route definitions below 
     }]); 

您还需要在HTML视图中设置base标题元素。这被angular用来确定构建URL时应该使用的路径。这个例子将使用根。

<!doctype html> 
<head> 
    <title>Laravel</title> 
    <base href="/" /> 
</head> 
+0

是否没有其他方式指定基地Angular?使用该标签会破坏正常的片段链接,例如''在URL路径'/ foo /'的页面不会进入'/ foo /#bar'。 – Walf

+0

是的,这是正确的,但如果我可以刷新我的网页,它会显示错误,如页面找不到laravel。所以我认为我们需要为它设置.htaccess。所以它在CI​​中工作就像上面的规则一样,我不设置它laravel。如果您知道,请告诉我们。 – Kamlesh

+0

你可以在laravel中捕捉路由,你不需要'.htaccess'修改。 'Route :: any('{path?}',function(){return view(“index”);}) - > where(“path”,“。+”);'注意结尾的位置这将匹配所有未定义的路由并返回角度应用程序。 –