I'm trying to describe a route with get params in my platform-server
/universal
app but so far without any success.
Anyone have an idea how to define achieve that?
Based on what I know from express
routing I tried the following but I end up facing an error
routes.ts:
export const ROUTES: string[] = [
'/',
'/item/:id'
];
main.server.ts:
ROUTES.forEach((route: string) => {
app.get(route, (req: Request, res: Response) => {
res.render('../dist/index', {
req: req,
res: res
});
});
});
my component:
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
console.log(params['id']);
});
}
With this code, server npm start
is starting without error but when I call http://localhost:8000/item/thisistheparam
I face following error in the browser console
Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'item/thisistheparam'