Skip to content

How to concatenate URLs to avoid getting TypeError [ERR_INVALID_URL]: Invalid URL #2297

Closed Answered by jan-molak
ChandanHackerrank asked this question in How to... ?
Discussion options

You must be logged in to vote

Hey @ChandanHackerrank

The root cause of the issue you're seeing is that the code sample concatenates the URL with the description of the questionID question, instead of the value of the question.

Since the url contains the description, it doesn't match any registered window URLs.

const url = '/questions/datascience/'+questionID.toString()+'/edit'
// produces: '/questions/datascience/description of questionID/edit'

Questions are asynchronous data structures, so to concatenate the value of a question with a static string or with the value of another question, you'll need to use the helper function called q.

In your case, this gives us:

const url = q`/questions/datascience/${ questionID }/e…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@ChandanHackerrank
Comment options

@jan-molak
Comment options

Answer selected by jan-molak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2294 on April 02, 2024 10:45.