Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Angular Router

You're reading from   Angular Router From Angular core team member and creator of the router

Arrow left icon
Product type Paperback
Published in Mar 2017
Publisher Packt
ISBN-13 9781787288904
Length 118 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Victor Savkin Victor Savkin
Author Profile Icon Victor Savkin
Victor Savkin
Arrow right icon
View More author details
Toc

Matching strategies


By default the router checks if the URL starts with the path property of a route, that is, it checks if the URL is prefixed with the path. This is an implicit default, but we can set this strategy explicitly, as follows:

// identical to {path: 'a', component: ComponentA}

{path : 'a' , pathMatch:'prefix',component: ComponentA}

The router supports a second matching strategy-full, which checks that the path is "equal" to what is left in the URL. This is mostly important for redirects. To see why, let's look at this example:

[
  { path: '', redirectTo: '/inbox' },
  {
    path: ':folder',
    children: [
      ...
    ]
  }
]

Because the default matching strategy is prefix, and any URL starts with an empty string, the router will always match the first route. Even if we navigate to /inbox, the router will apply the first redirect. Our intent, however, is to match the second route when navigating to /inbox, and redirect to /inbox...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime