Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular routing not working i firebase hosting

I have a Angular project where routing works in localhost, but when I deploy my project to Firebase hosting only the base-url works. Here is my routing: Example https://baseurl/jegharaldrigkategori does not work in Firbase hosting. It says "Page not found"

  const routes: Routes = [
  {
      path: '',
      redirectTo: 'home', 
      pathMatch: 'full'
  },
  {
    path: 'home', 
    component: HomeComponent
  },
  {
    path: 'jegharaldrigkategori', 
    component: JegharaldrigkategoriComponent
  },
  {
    path: 'jegharaldrig', 
    component: JegharaldrigComponent
  },
  {
    path: 'udfordring', 
    component: UdfordringComponent
  },
  {
    path: 'terning', 
    component: TerningComponent
  },
  {
    path: 'overunder', 
    component: OverunderComponent
  }
];
like image 685
Loc Dai Le Avatar asked Oct 13 '25 09:10

Loc Dai Le


1 Answers

When hosting on firebase you must remember to redirect all calls to index.html.

The hosting portion of your firebase.json should include "rewrites", here's an example :

"hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },
like image 150
Segev -CJ- Shmueli Avatar answered Oct 15 '25 14:10

Segev -CJ- Shmueli