Currently, we use a switch statement and regex patterns to determine the prefix for each page's <title /> HTML tag
for SEO in the PageTitle component.
switch (true) {
case title.length > 0:
pageTitle = `${title}`
break
case home:
pageTitle = `${appName} - Search for harmonized transcriptome data`
break
case /\/about$/.test(path):
pageTitle = `About`
break
case /\/dataset/.test(path):
pageTitle = `Dataset -`
break
case /\/download/.test(path):
pageTitle = `Download Dataset -`
break
case /\/license$/.test(path):
pageTitle = `License -`
break
case /\/privvacy$/.test(path):
pageTitle = `Privacy -`
break
case /\/terms$/.test(path):
pageTitle = `Terms of Use -`
break
default:
break
}
In this issue, we want to replace the switch with an if statement, and instead of using regex, we'll define all prefix values for the pages using an object.
Problem or idea
To achieve this, we should make the following changes to PageTitle:
Add a new object containing all possible prefixes for the pages
Add a new helper method that returns the appropriate prefix based on the route values
Solution or next step
In PageTitle:
Add a new constant object,titlePrefixes, to store prefix values for pages
Add a new helper getPageTitle that does the following:
Takes a route path as its argument
Returns the corresponding prefix value using if and titlePrefixes
Context
Currently, we use a
switch
statement and regex patterns to determine the prefix for each page's<title />
HTML tag for SEO in thePageTitle
component.In this issue, we want to replace the
switch
with anif
statement, and instead of using regex, we'll define all prefix values for the pages using an object.Problem or idea
To achieve this, we should make the following changes to
PageTitle
:Solution or next step
In
PageTitle
:titlePrefixes
, to store prefix values for pagesgetPageTitle
that does the following:if
andtitlePrefixes