SOLVED: Creating a dynamic link based on title

My code below almost works but is only grabbing the first word of my title. For example, the title of my record is “This is a test”. The code is only grabbing “This”. It seems to stop at the space so I get an error
/bug-reports/this Does not exist. Any way to resolve this?

export function addimages_click(event) {
var bug_title = local.getItem( “bug_title” );
wixLocation.to( “/bug-reports/” + bug_title);
}

Still trying to figure this out if anyone has any input.

Try this, perhaps this works for you…

exportfunction addimages_click(event) {
	let bug_title = local.getItem("bug_title");
	let myURL = "/bug-reports/" + (bug_title).toString()
	console.log (myURL)
	wixLocation.to(myURL); 
}

@russian-dima unfortunately I get the same results. I wonder if I need to replace the spaces in the code before passing it to the location. My expertise is sql and I know how to do it there but not sure how to do it with javascript.

I tried this code but its only replacing the first space it finds. ANy idea how to make it replace all spaces?

export function addimages_click(event) {
let bug_title = local.getItem( “bug_title” );
let myURL = “/bug-reports/” + bug_title.replace( ’ ’ , ‘%’ )
console.log (myURL)
wixLocation.to(myURL);
}

Got it!, thanks for the help

export function addimages_click(event) {
let bug_title = local.getItem( “bug_title” );
let myURL = “/bug-reports/” + bug_title.replace(/\s+/g, ‘-’ )
console.log (myURL)
wixLocation.to(myURL);
}