Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular routing in a sub-folder not working

Tags:

angular

I am deploying an Angular App in a sub-folder. Landing page works fine. But other routers are not working. Showing 404 error.

For Ex:

www.xxx.com/demo -> Loads landing page.

www.xxx.com/demo/about -> Showing 404 error.

I have tried below commands to build application.

ng build --prod --base-href /demo/

ng build --prod --base-href /demo/ --deploy-url /demo/ 

I have hosted my application here.

Am I missing something?

like image 665
Debabrata Patra Avatar asked Apr 13 '26 05:04

Debabrata Patra


1 Answers

Seems that your server is not serving index.html for every call beyond the angular route, so it doesn't "allow angular to handle" the route change.

I guess, adding useHash: true to the routes import, would solve it.

@NgModule({
    imports: [RouterModule.forRoot(routes, {useHash: true})]
})

This will add a hash (#) to your urls, making sure the routing stays client-side.

like image 184
Stavm Avatar answered Apr 16 '26 01:04

Stavm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!