1

im passing slug by router.navigate to use slug in another component

GetTagPost(slug) {
  return this.router.navigate(["blog/view-hot-tags/", slug])
}

i should have url like: http://localhost:4200/blog/view-hot-tags/bb

but angular will turn it like:

http://localhost:4200/blog/view-hot-tags;0=bb

why???

other route for example documents/single-view/:id' work correctly and parameter will seprate by "/" not ";" any idea ???

router.ts:

  {path: 'documents',component: DocsComponent},
  {path: 'documents/single-view/:id', component: ViewSingleDocComponent},
  {path: 'documents/single-cat-view/:id', component: ViewSingleCatDocComponent},
  {path: 'blog/:id', component: ViewSingleBlogComponent},
  {path: 'blog/view-hot-tags/:id', component: ViewBlogByTagComponent},
  {path: 'loginM', component: LoginComponent},
  {path: 'login', component: LoginNmComponent},
  {path: '', component: ProductComponent, pathMatch: 'full', 
     data: {breadcrumb: "home"},
  },

component.html:

    <div class="tag_name">
      <a (click)="GetTagPost(tag?.tag)">#{{tag?.tag}}</a>
    </div>

component.ts:

  GetTagPost(slug) {
    return this.router.navigate(["blog/view-hot-tags/", slug])
  }
5
  • Have you tried to see what your slug looks like ? Commented Jul 2, 2018 at 19:59
  • yes its a simple string it "bb" for test Commented Jul 2, 2018 at 20:01
  • How about a working sample? stackblitz.com Commented Jul 2, 2018 at 20:14
  • 1
    My bet is that it's not 'bb', but an array containing a single element 'bb'. Commented Jul 2, 2018 at 21:18
  • oh you right @JBNizet its a array angular try to use it as string thanks all Commented Jul 3, 2018 at 4:27

1 Answer 1

1

Try

GetTagPost(slug) {
return this.router.navigate(["blog/view-hot-tags", { id : slug }]); }

It would provide http://localhost:4200/blog/view-hot-tags?id=bb and it would work fine. It is querystring format.

OR

GetTagPost(slug) {
return this.router.navigate(["blog/view-hot-tags/"+slug ]); }

I would provide http://localhost:4200/blog/view-hot-tags/bb

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

3 Comments

Why are you getting that semicolon, and what do you want it to be??
I updated the answer, if none of these are working, then you are not sharing the error causing code.
hi thanks for help i found the problem was the slug ,value it seems its a array i cast it as string

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.