使用PathLocationStrategy时如何配置apache2以允许多层路由

时间:2019-05-20 04:37:30

标签: angular apache2

我使用PathLocationStrategy是因为我不想在我的URL中显示#。

请参阅this tutorial,我配置了apache2,并且浏览器刷新在第一个路由级别(my-app / items)运行良好。

在第二级(my-app / items / item1)中,浏览器刷新将返回白屏,并在控制台中显示错误:

  

未捕获到的SyntaxError:意外令牌<< / p>

这是我的app.module.ts

 providers: [
        {provide: LocationStrategy, useClass: PathLocationStrategy},

这是我的apache2配置

<Directory /path/to/app>
        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.html [L]
    </Directory>

0 个答案:

没有答案