question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 4 Route fails if added parameter with hyphen

See original GitHub issue

I am using Angular 4 and if I use hyphen between parameters instead of slash, the route does not work as expected. Here is my route:

{ path: ':bookId/:pageFrom-:pageTo', component: BookComponent }

I was expecting to receive the values of pageFrom and pageTo in separate params but I am receiving it in pageFrom-:pageTo. I have also tried to escape the hyphen with \ but that also does not work.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
zishanjcommented, Jun 27, 2017

I have other ideas also to implement it like splitting the string later by hyphen… But I am looking for something more genuine like this { path: ':bookId/:pageFrom-:pageTo', component: BookComponent } which will allow the use of hyphen - as separator instead of /

This is also useful for my visitors to use shortest/simple possible link instead of providing custom query parameters.

3reactions
okYadavcommented, Jun 24, 2017

Use following code this.

{ path: ':bookId', component: BookComponent }

In your component do

constructor(private _activatedRoute: ActivatedRoute) {
    this._activatedRoute.params.subscribe(v => {
            // You can get param here v['pageFrom'];
            // You can get param here v['pageTo'];
    });
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular path with hyphen character not allowed - Stack Overflow
The path is not changed but it works when I use following: $location.path('/product/ninja_game');. Is there anything specific to hyphen/dash ...
Read more >
A Single Route Parameter Can Match Multiple URL Segments ...
Ben Nadel demonstrates that route parameters can match multiple URL segments in Angular 4.4.4. This allows us to capture entire URL suffixes ...
Read more >
Common Routing Tasks - Angular
This topic describes how to implement many of the common tasks associated with adding the Angular router to your application.
Read more >
Razor Pages route and app conventions in ASP.NET Core
To specify a page route, add route segments, or add parameters to a route, use the page's @page directive. For more information, see...
Read more >
Overview - Reach Router
Reach Router is a small, simple router for React that borrows from React Router, Ember, ... Router manages the focus of your app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found