I have read a couple of tutorials about SPA and client-side routing. But I am not getting it completely. How can I setup the router to work without a web server.
Example: file:///C:/cxr/CXR-WebViews/dist/CXR-WebViews/index.html#/products/vat
The browser will accept this as index.html but should i use router fragments for calling components?
I can't use the parameter useHash:true in the router because the resulting url: ".../index.html/#/products/vat" will not find the file. This would only work if it was a webserver call that can redirect requests to index.html.
app-routing.module.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { ProductGroupsComponent } from './products/product-groups/product-groups.component';
import { VatComponent } from './products/vat/vat.component';
import { ProductComponent } from './products/product/product.component';
import { AppComponent } from './app.component';
const routes: Routes = [
{ path: '', component: AppComponent, pathMatch: 'full' },
{ path: 'products', component: AppComponent, children:[
{ path: 'productGroups', component: ProductGroupsComponent },
{ path: 'vat', component: VatComponent},
{ path: ':id', component: ProductComponent }
]}
];
@NgModule({
imports: [RouterModule.forRoot(routes, { useHash: true })],
exports: [RouterModule]
})
export class AppRoutingModule {}
It must be something stupid that i am doing wrong. I just cant find it. I build with: ng build --prod --base-href ./