首页 文章

Angular 5路由问题

提问于
浏览
0

我使用Angular 5作为我的前端应用程序,使用Java作为服务器端的东西 . 我对Angular路由有一个问题 .

我的问题是:

当用户在其浏览器URL栏中输入此URL http://example.net/public/public-data 并点击输入时,他获得 404 . 由于此请求的资源在服务器上不可用,所以为了解决这个问题,我写了 .htaccess 文件,将每个请求重定向到 index.html 页面 .

在此更改之后, 404 问题已解决但我遇到的一个新问题,

新问题是:当用户点击http://example.net/public/public-data时,他会被重定向到index.html页面,现在我不知道他最初请求了哪个页面 .

我怎么知道原始网址?

EDIT

这是我的 .htaccess 文件的代码

<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.html [QSA,L]
</ifModule>

NOTE

我正在使用子文件夹,例如, http://example.net/public/public-data 这里public是我的子文件夹,其中放置了我的Angular应用程序代码 . 并且 http://example.net 包含一些与我的Angular应用程序没有任何连接的 .php 文件 .

1 回答

  • 0

    删除.htaccess代码并使用 <base href="/public/">

    您的.htaccess将始终检查index.html以外的路径并重定向到它 .

    index.html

    <head>
    <base href="/public/">
    <!-- Rest of your code here -->
    </head>
    

相关问题