My routing doesn't work when I try to refresh an existing page

882 Views Asked by At

I have done my routing using angular 7 and it works fine if I follow the path using my menu key. But if I am on a page and tries to refresh the browser it gives me 404 error. Similary I cannot directly access any single page, I have to go to all pages using the buttons. Example of my code: this is part of my routing file

const routes: Routes = [
  {
    path:'',component:Component1
  },
  {
    path: 'home', component: Component2
  }]

my index has bas ref as:

<base href="/myforms/">

and I am accessing the component2 using the following:

<div class="col-sm-6">
              <a routerLink="home" router-link-Active="active" ><button class="btn btn-green">Home</button></a>              
            </div>

and it works fine I get the url: localhost:8091/myforms/home and it opens when I click the button. But if I refresh my page it gives me 404.

Kindly help me if you know anything regarding this issue. Thankyou in advance.

0

There are 0 best solutions below