Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix optional laravel route parameters #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

whitespacecode
Copy link

Update laravel-routes.js to fix having optional route parameters

Update laravel-routes.js to fix having optional route parameters
@whitespacecode
Copy link
Author

Fix for optional parameters in the laravel route "/teams/{team}/dashboard/{style?}"

uri = uri.replace(
     new RegExp(`{${parameter}[^}]*}`),
     parameters[parameter]
);

In this example, the regular expression /{style[^}]*}/ will match {style} or {style?} in the string variable.
The [^}] part of the regular expression matches any character that is not a closing curly bracket (}), and the * character matches zero or more of the preceding character or group. This allows the regular expression to match any characters between the {style and } parts of the string.

@devnll
Copy link

devnll commented Jul 22, 2023

I just ran into this myself, but the regex I came up with is a little different. The problem I see with the one proposed here is that it will also match for example {styleName}. Here's my version, which only adds support for an optional ? after the parameter name: #83

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants