Angular 9 - When I paste the absolute link of an internal link of my site it gives error

Asked

Viewed 49 times

0

For example: Link to the Portfolio: http://www.impactodesigner.com.br/portfolio/

If I paste into the browser already with an internal link it gives error, for example: http://www.impactodesigner.com.br/portfolio/curriculum

I don’t know if at build time I have to do something, I’m specifying like this: ng build --base-href http://www.impactodesigner.com.br/portfolio/

And on the metatag in "dist/index.html" he puts this (remembering that it is a domain):

<base href="http://www.impactodesigner.com.br/portfolio/">

2 answers

0

I solved the problem with . htaccess

<IfModule mod_rewrite.c>
    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]
</IfModule>

0

Angular paths are not recognized by the server.

You need to properly configure the web config. server, below an example for IIS.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Angular Routes" stopProcessing="true">
                    <match url=".*" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="./index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
  • vc. meant IIS or ISS, my hosting is Linux.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.