Search code examples
htmlangularhrefangular2-routing

Add context path Angular 2


I want to run my app instead of http://localhost:4200 at http://localhost:4200/pilot/.

I'm trying to change the base href at index.html but I get Uncaught SyntaxError: Unexpected token <

This is my index.html

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>PrimengQuickstartCli</title>
  <base href="pilot/"/>

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

And my app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';

import { MessagesModule } from 'primeng/primeng';
import { InputTextModule } from 'primeng/primeng';
import { PasswordModule } from 'primeng/primeng';
import { ButtonModule } from 'primeng/primeng';
import { DataTableModule, SharedModule } from 'primeng/primeng';
import { DialogModule } from 'primeng/primeng';

import { CarService } from './service/carservice';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ButtonModule,
    MessagesModule,
    InputTextModule,
    PasswordModule,
    ReactiveFormsModule,
    DataTableModule,
    SharedModule,
    DialogModule
  ],
  providers: [CarService],
  bootstrap: [AppComponent]
})
export class AppModule { }

Should I change the folder structure?

I appreciate any help.


Solution

  • At the end with this was enough in my index.html:

    <base href="/pilot/">