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.

Optional parameters in routes

See original GitHub issue

Is it possible to have an optional route parameter?

in react-router we had routes like this… route url /requests/shift(/:id) which allowed us to both navigate to /requests/shift and requests/shift/1

im not seeing a documented way to do this with navi, am i just missing something?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
th3fallencommented, Apr 19, 2019

Good to know, i’ll give that a shot

1reaction
jamesknelsoncommented, Apr 19, 2019

It’s possible to achieve a similar result by passing the same matcher to both / and /:id, like so:

let matcher = map(({ params }) =>
  route({
    view: <div>Hello {params.id || 'world!'}</div>
  })
)

mount({
  '/': matcher,
  '/:id': matcher,
})

I don’t think this behaves exactly the same as optional routes, but does it cover your use case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Optional parameters in Web API Attribute Routing
Optional Parameters in Web API Attribute Routing and Default Values: ... You can make a URI parameter as optional by adding a question...
Read more >
Angular Routing Parameters (Required Param,Optional ...
These Parameter are used when they are optional and we need to pass complex and multiple parameters . Optional parameter is not used...
Read more >
Passing route control with optional parameter after root in ...
I would like to remove the /l/ from my route (to make my url's shorter) and make the :key parameter optional. Would this...
Read more >
Passing Optional Parameters to a Route - Rangle.io
Query parameters allow you to pass optional parameters to a route such as pagination information. ... The key difference between query parameters and...
Read more >
React Router: Optional Parameters - DigitalOcean
The route will be rendered if it matches the path, with or without the optional parameter. So '/Lyrics/Spoonman' and '/Lyrics/Spoonman/3' would ...
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