FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 283   



You cann't put the title as is in urls as it may contain spaces/ special characters etc, The better option is generating a url friendly String out of Title.
For example instead Title to url friendly String generation its better have some thing like title-to-url-friendly-string-generation in urls. So basically i am replacing all special characters including spaces with - (Hyphen) and maintaining a constant case (Lower case). For this i have written a function for which you can pass your original Title and it returns the url friendly string.

function getLinkFromtitle(title) {
  if (title) {
    title = title.toLowerCase();
    title = title.replace(/\W+/g, "-");
    return title;
  }
  return title;
}

Testing

console.log(getLinkFromtitle('Title to url friendly String generation'));
// this outputs : title-to-url-friendly-string-generation



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News