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.

Router: Multiple optional parameters support

See original GitHub issue

As a developer I want to have the same view being accessible using different routes with different parameters. For example:

  1. /forum/thread/<threadId> opens the thread view
  2. /forum/thread/<threadId>/<messageId> opens the same thread view and scrolls to specified message
  3. /forum/message/<messageId> – same as above, but retrieves the threadId first, based on messageId

In current implementation we have

@Route(value = FORUM_THREAD_ROUTE /* /forum/thread */, layout = ForumView.class)
@RouteAlias(value = FORUM_MESSAGE_ROUTE /* /forum/message */, layout = ForumView.class)

and then

	@Override
	public void setParameter(BeforeEvent event, @WildcardParameter String parameter) {
		if(StringUtils.isNotEmpty(parameter)) {
			if (event.getLocation().getPath().startsWith(FORUM_THREAD_ROUTE)) {
				String[] segments = parameter.split("/");
				if (segments.length >= 1) threadIdParam = segments[0];
				if (segments.length >= 2) messageIdParam = segments[1];
			} else {
				String[] segments = parameter.split("/");
				if (segments.length >= 1) messageIdParam = segments[0];
			}
		}
	}

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
fluorumlabscommented, Sep 18, 2018

There is now an implementation available as extension to Vaadin Flow by @fluorumlabs : https://vaadin.com/directory/component/url-parameter-mapping

Yeah, that’s me, the OP

2reactions
samiecommented, Sep 11, 2018

There is now an implementation available as extension to Vaadin Flow by @fluorumlabs : https://vaadin.com/directory/component/url-parameter-mapping

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Optional Params in React Router - Stack Overflow
I've got a situation where I need to support the following use case. I've got React component that is accessed via /project/1234 ....
Read more >
How can i pass more one optional parameter in the route
i am trying to pass more then one optional Parameter in my route. Copy Code 'middleware' => 'auth:api', 'prefix' => 'api/v1' ], function...
Read more >
Multiple optional parameters in the url - MSDN - Microsoft
User208219337 posted. I am working on an MVC app. I have to return the images based on the parameters passed in the URL....
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 >
Optional route parameters - Blazor University
Optional route parameters aren't supported explicitly by Blazor, but the equivalent can be easily achieved by adding more than one @page declaration on...
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