Routing problem after final build in angular 2

Asked

Viewed 485 times

0

After generating a final build in angular 2 ng build --prod I was able to put it on any server (Nginx/Tomcat/others...) normally, the problem happens that the routing does not work using the tag <router-outlet> and the app.routing.ts file to configure the routes. Someone has already gone through this?

3 answers

0


0

Maybe you’re using something like

<a class="nav-link" href="/contatos">Contatos</a>

Using the href="Diretório-da-rota" works until you do the build and then it doesn’t work anymore. You should use the routerLink="Diretório-da-rota". Example:

<a routerLink="/contatos" class="nav-link">Contatos</a>

0

Simple if you have to put in a folder use :

ng build --base-href /myUrl/ or ng build --bh /myUrl/

For example I have to put the site in a directive called site2 then ng build --bh /site2/

More Information https://github.com/angular/angular-cli/wiki/build

Browser other questions tagged

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