2

I am trying to load an angular component based on same parameters provided in router path. My path looks like such.

  {
    path: ':code/:country',
    component: CardViewComponent,
    resolve: {
      configuration: CardViewService
    }
  },

First, i am lazy loading my module and in that nodules router i am trying to load the above component. The lazy loading of the module is

 {
    path: 'main/chapters',
    loadChildren: () => import('./features/chapter.module').then(m => m.ChapterModule),
  },

Every thing works fine but the problem arises when () are passed in as the parameter for this route. For example

/main/chapters/Au/Australia

results in proper output but when it becomes something like

/main/chapters/Au/Australia(Old)

The component is not loaded. But again if the brackets are removed then every thing works fine. I have tried encodeUriComponent but it did not help. And changing the url is not an option for me.

Can any body guide me with this. I have also searched for github issues https://github.com/angular/angular/issues/10280 but could not get much out of it. Really looking forward to some solutions.

1 Answer 1

2

The workaround provided in the GitHub link does work.

encodeURIComponent(str) {
  return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
    return '%' + c.charCodeAt(0).toString(16);
  });
}

const url = `/main/chapters/Au/${this.encodeURIComponent('Australia(Old)')}`;
this.router.navigate(url);

Github Issue

Stackblitz

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.