Skip to content

Commit

Permalink
PR feedback - use regex in the path replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
fdm1 committed Jan 24, 2023
1 parent aff2134 commit 233a810
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion runtime/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function populateUrl(path, params, inheritedParams) {
const queryString = getQueryString(path, params)

for (const [key, value] of Object.entries(allParams))
path = path.replace(`:${key}`, value)
path = path.replace(new RegExp(`:${key}(\/|$)`), value)

return `${path}${queryString}`
}
Expand Down

3 comments on commit 233a810

@Romkar
Copy link

@Romkar Romkar commented on 233a810 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in (https://github.com/roxiness/routify-starter) project with routify v2.18.10
I have a bug: in file (routify-starter\src\pages\example_components\CrudWidget_view.svelte)
line 20 <a href={$url('../:id/update', { id })}>[Update]

url should be render as 'http://127.0.0.1:5000/example/widget/2/update'
but it 'http://127.0.0.1:5000/example/widget/2update'

If I use routify v2.18.8, url is good.

bug

@fdm1
Copy link
Author

@fdm1 fdm1 commented on 233a810 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested out and confirmed. One idea, break up the end of string use case from the internal params use:

  for (const [key, value] of Object.entries(allParams)) {
    if (path.endsWith(`:${key}`)) {
      path = path.replace(new RegExp(`:${key}($)`), value)
    }
    path = path.replace(new RegExp(`:${key}(\/)`), `${value}/`)
  }

@fdm1
Copy link
Author

@fdm1 fdm1 commented on 233a810 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a separate PR for this: #504

Please sign in to comment.