Home > Blockchain >  url with query params redirecting to / in angular
url with query params redirecting to / in angular

Time:09-29

In my application I am using lazy loading. Here is the app.module.ts

const appRoutes: Routes = [
    {
        path: "your-app",
        canActivate: [AuthGuard],
        loadChildren: "app/components/your-app/your-app.module#YourAppModule"
    },
    {
        path: "my-app",
        canActivate: [AuthGuard],
        loadChildren: "app/components/my-app/my-app.module#MyAppModule"
    },
    {
        path: "**",
        redirectTo: "/"
    }
];

and my child module

export const routes: Routes = [
    {
        path: "",
        component: MyAppComponent
    }
];

and when I hit http://localhost:4200/#/my-app?myParam=test

it redirect me to http://localhost:4200/#/

is there any thing missing?

CodePudding user response:

Just for the others if somebody else would be looking for solution in case of similar issues - check your guard as it can block your access to the path. It was also an issue here (see: comments to the question).

CodePudding user response:

It should be like this

{
     path: "your-app",
     canActivate: [AuthGuard],
     loadChildren: "app/components/your-app/your-app.module#YourAppModule"
}

In component.ts file from where user want to redirect --

this.router.navigate(['/your-app'], {
      queryParams: {
        myParam: your_value, 
      },
    });
  • Related