Change news item urls to /news, replace space with underscore

This commit is contained in:
Felix Ableitner 2022-03-07 19:37:22 +01:00
parent 88c381712d
commit 8c056cfc10
3 changed files with 7 additions and 2 deletions

View file

@ -19,6 +19,7 @@ export class NewsItem extends Component<any, any> {
get markdown(): string {
let title = decodeURIComponent(this.props.match.params.title);
title = title.replace(/_/g, " ");
return news_md.find(v => v.title == title).markdown;
}

View file

@ -30,7 +30,7 @@ export class News extends Component<any, any> {
<ul>
{newsReversed.map(v => (
<li>
<Link to={`news_item/${v.title}`}>{v.title}</Link>
<Link to={`news/${titleToUrl(v.title)}`}>{v.title}</Link>
</li>
))}
</ul>
@ -39,3 +39,7 @@ export class News extends Component<any, any> {
);
}
}
function titleToUrl(title: string): string {
return title.replace(/ /g, "_");
}

View file

@ -31,7 +31,7 @@ export const routes: IRouteProps[] = [
component: Releases,
},
{
path: `/news_item/:title`,
path: `/news/:title`,
exact: true,
component: NewsItem,
},