How to set base url for Angular application

Better to do it when you build project. Like this:

ng build --prod --base-href=/test/

You can modify it using <base href="/"> in src/index.html file.

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>SiteFrontend</title>
    <base href="/test">   //<------ this line

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
    <app-root></app-root>
</body>


Please follow these following steps:

  1. Set useHash: false in app-routing-module.ts
  2. In index.html, change <base href="./" /> to <base href="/" />