javascript - Angular - Making String Safe for URL - Is Route this correct? -


to make app seo friendly/easier users read urls i'm appending title of page clicked on each url.

so example if user clicks on story 'asia stocks climb' sent url:

mysite.com/story/34324/asia-stocks-climb 

in routes.js specify url containing text @ end exist ignore it:

.when("/story/:id/:pagetitle",     {       templateurl: "views/story.html",       controller: 'story' ,       controlleras: 'story'     }   ) 

so questions:

1 - ok (for seo) append end of urls when clicked?

2 - text story 'asia stocks climb' become url friendly 'asia-stocks-url' i'm using own code:

textcontent.trim().tolowercase().replace(/ /g,'-').replace(/[^\w-]+/g,'') 

i've tested , seems ok there angular method this?

thanks.

that's 100% correct, use this:

$scope.slugify = function (text) {   if (text == null || text == 'undefined')      return "";    return text        .tolowercase()        .replace(/[^\w ]+/g, '')        .replace(/ +/g, '-'); } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -