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.

Route priorities

See original GitHub issue

Hi, in my project I along with route path like /welcome, /sign_in (specific string matched) I have also path /:id. I’ve found only way to match this route is to place it on top of routes so it looks like:

const routes = [
  { path: '/:id', name: 'idRoute' },
  { path: '/welcome', name: 'welcome' },
  { path: '/sign_in', name: 'signIn' }
];

And it seems kind of strange for routes to be resolved bottom->top, wouldn’t it make more sense to go top->bottom? So it checks all routes first and if none matches then it comes to /:id ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
frenzzycommented, Aug 5, 2016

Yes, because the action method of a route will have to return anything different from undefined to stop iterating and finish routing process.

const anyRoute = {
  path: '/'
  action() {
    if (condition) {
      return undefined // skip this route
    }
    return 'page'
  }
}

Playground: https://jsfiddle.net/frenzzy/ko22k9cg/1/

2reactions
frenzzycommented, Aug 5, 2016

The ordering works the same way as in express. So :id param matches everything and next route will not be called. Playground: https://jsfiddle.net/frenzzy/ko22k9cg/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Route Precedence -- How does a Router choose its preferred ...
The three attributes for Route Preference are the Route Specificity, the Administrative Distance, and the Metric. If multiple routes exist and ...
Read more >
Configure Route Selection for Routers - Cisco
This document describes how routers work, are configured, and how to select a route for them.
Read more >
Linux for Network Engineers: How to Set Route Priorities
In this Linux for Network Engineers post, learn how to set and prioritize a route on Linux.
Read more >
Route Prioritizing - SonicWall Online Help
Traditionally, routes have been prioritized based on the specificity of the destination IP address. Routes with longer prefixes (more specific) have a higher ......
Read more >
ip route priority high — router - Cisco IOS in a Nutshell, 2nd ...
This command assigns a high priority to an IS-IS prefix, which means routes with the specified tag are marked for faster processing and...
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