0

I am working on a simple angular 2 application and routing does not seem to be working for me.

When I am trying to do routing for my application with a url like myapp.com/15/hello, the url parameters are preserved with non hash routing with the code like this

RouterModule.forRoot([
    { path: '**', component: MyComponent },
])

However when I move to useHash routing, if i try to do the same request myapp.com/15/hello, the parameters extra parameters are stripped from the url and becomes like this : myapp.com/#/

RouterModule.forRoot([
    { path: '**', component: MyComponent},
],
    {
        useHash: true,
    })

Is there any way to usehash navigation without it stripping the extra parameters from the url?

Thank you

James
  • 557
  • 1
  • 12
  • 29

2 Answers2

0

The path '**' is used for undefined routes. You should instead use '' to route to myComponent:

{
    path     : '',
    component: myComponent
}
Ashish Koshy
  • 131
  • 1
  • 7
  • 1
    Hi, Thank you for your response. I have tried this and it still strips the url from myapp.com/15/hello to myapp.com/#/ – James Apr 27 '18 at 22:30
0

I had the same problem. My solution was to remove the

<base href="/">

from the header. This works only if you use the "useHash" Routing strategy. I hope this solves your problem.

MF Jones
  • 16
  • 2