8

My angular route config is as below:

export const routes: Routes = [
  { path: 'mgmt', ... },
  { path: 'about', ... },
  { path: '**', component: PageNotFoundCmp }
];

But now on a page, there's a link (<a href="/help/en/index.html" target="_blank">) to help pages, which are static resources hosted on the same server. With the above route config, apparently it will be matched to others ** - page not found.

Let's say we cannot host help resources in another domain, is there any way to exclude /help/** path from angular routing? or do you think this is a valid feature request for angular to support?

Roy Ling
  • 1,592
  • 1
  • 14
  • 31
  • 1
    I think you should configure server not to redirect to `index.html` from `/help/**` path – yurzui Apr 19 '17 at 08:26
  • Any luck ???????? – mp3por Jul 04 '17 at 11:30
  • @mp3por this is not supported in angular for now, so I choose to create a dedicated context for all angular routes, while `/help/*` static resources is still served by the same server. – Roy Ling Jul 13 '17 at 09:33
  • Did you find a solution for that? – Khaled Ramadan May 24 '18 at 09:48
  • @KhaledRamadan as I commented above, I added a context for angular app. Using base href in my case, all angular routes are now `/ui/**`, and I added necessary config in server end so that all `/ui/*` requests are routed to `index.html` (client routing), while `/help/*` is routed to static help resources. – Roy Ling May 31 '18 at 10:48
  • ok @RoyLing thanks for your reply – Khaled Ramadan May 31 '18 at 10:51
  • 1
    Have you seen this Post? https://stackoverflow.com/questions/40150393/how-to-redirect-to-an-external-url-from-angular2-route-without-using-component – Silvester Schn. Mar 03 '21 at 11:57
  • @SilvesterSchn. Thanks for sharing the link, and that's another interesting topic, but not exactly the same problem I was trying to solve in this question though. – Roy Ling Mar 03 '21 at 13:23

1 Answers1

0

As mentioned here angular 2 exclude url in routing the only solution seems to set useHash: true in your RouterModule config:

@NgModule({
  imports: [
    RouterModule.forRoot(
      [
        {
          path: 'login',
          loadChildren: './login/login.module#LoginModule'
        },
        {
          path: '**',
          redirectTo: ''
        },
      ],
      {
        useHash: true,
        onSameUrlNavigation: 'reload'
      }
    )
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }
ratfury
  • 203
  • 2
  • 9