Skip to content

Commit

Permalink
Merge pull request #197 from traPtitech/fix/router-link
Browse files Browse the repository at this point in the history
router-linkのto属性でオブジェクトを使用するように
  • Loading branch information
ogu-kazemiya authored Oct 19, 2024
2 parents 07be87d + 60ba8a9 commit d6ab9cc
Show file tree
Hide file tree
Showing 24 changed files with 71 additions and 32 deletions.
5 changes: 4 additions & 1 deletion src/components/Contest/ContestTeamListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ defineProps<{
<li :class="$style.container">
<router-link
:class="$style.link"
:to="`/contests/${contestId}/teams/${contestTeam.id}`"
:to="{
name: 'ContestTeam',
params: { contestId: contestId, teamId: contestTeam.id }
}"
>
<span :class="$style.name">{{ contestTeam.name }}</span>
<span v-if="contestTeam.result" :class="$style.result">
Expand Down
5 changes: 4 additions & 1 deletion src/components/ContestTeam/MemberListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/users/${member.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: member.name } }"
>
<user-icon :class="$style.icon" :user-name="member.name" :size="32" />
<p :class="$style.name">{{ member.name }}</p>
</router-link>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Contests/ContestListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/contests/${contest.id}`">
<router-link
:class="$style.link"
:to="{ name: 'Contest', params: { contestId: contest.id } }"
>
<span :class="$style.name">{{ contest.name }}</span>
<span :class="$style.date">
{{ getFullDayWithTimeString(new Date(contest.duration.since)) }} -
Expand Down
5 changes: 4 additions & 1 deletion src/components/Event/HostnameListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<div>
<router-link :class="$style.link" :to="`/users/${hostname.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: hostname.name } }"
>
<user-icon :class="$style.icon" :user-name="hostname.name" :size="128" />
<div :class="$style.desc">
<div :class="$style.name">{{ hostname.name }}</div>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Events/EventListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const date = computed(() =>

<template>
<div>
<router-link :class="$style.link" :to="`/events/${event.id}`">
<router-link
:class="$style.link"
:to="{ name: 'Event', params: { eventId: event.id } }"
>
<span :class="$style.name">{{ event.name }}</span>
<span :class="$style.date">({{ date }})</span>
</router-link>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Group/AdminListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/users/${admin.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: admin.name } }"
>
<user-icon :class="$style.icon" :user-name="admin.name" :size="32" />
<span :class="$style.name">{{ admin.name }}</span>
</router-link>
Expand Down
5 changes: 4 additions & 1 deletion src/components/Group/MemberListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/users/${member.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: member.name } }"
>
<user-icon :class="$style.icon" :user-name="member.name" :size="32" />
<p :class="$style.name">{{ member.name }}</p>
<p :class="$style.duration">
Expand Down
5 changes: 4 additions & 1 deletion src/components/Groups/GroupListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/groups/${group.id}`">
<router-link
:class="$style.link"
:to="{ name: 'Group', params: { groupId: group.id } }"
>
<span :class="$style.name">{{ group.name }}</span>
</router-link>
</li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Index/GroupList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const groups = computed(() =>
<router-link
v-for="group in groups"
:key="group.id"
:to="`/groups/${group.id}`"
:to="{ name: 'Group', params: { groupId: group.id } }"
:class="$style.link"
>
<img
Expand Down
3 changes: 2 additions & 1 deletion src/components/Layout/BreadCrumbTrail.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { RouteLocationNamedRaw } from 'vue-router'
import AIcon from '/@/components/UI/AIcon.vue'
export interface Path {
name: string
link: string
link: RouteLocationNamedRaw
}
defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion src/components/Layout/PageHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const { isMobile } = storeToRefs(responsiveStore)

<template>
<header :class="$style.container">
<router-link to="/">
<router-link :to="{ name: 'Index' }">
<img
:src="isMobile ? spLogo : pcLogo"
alt="traP"
Expand Down
5 changes: 4 additions & 1 deletion src/components/Project/MemberListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/users/${member.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: member.name } }"
>
<user-icon :class="$style.icon" :user-name="member.name" :size="32" />
<span :class="$style.name">{{ member.name }}</span>
<span :class="$style.duration">
Expand Down
5 changes: 4 additions & 1 deletion src/components/Projects/ProjectListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/projects/${project.id}`">
<router-link
:class="$style.link"
:to="{ name: 'Project', params: { projectId: project.id } }"
>
<span :class="$style.name">{{ project.name }}</span>
<span :class="$style.date">
{{ getGroupOrProjectDuration(project.duration) }}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Search/UserListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ defineProps<{

<template>
<li>
<router-link :class="$style.link" :to="`/users/${member.name}`">
<router-link
:class="$style.link"
:to="{ name: 'User', params: { userId: member.name } }"
>
<user-icon :class="$style.icon" :user-name="member.name" :size="32" />
<p :class="$style.name">{{ member.name }}</p>
</router-link>
Expand Down
5 changes: 4 additions & 1 deletion src/components/User/ContestsContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ defineProps<Props>()
<h2 :class="$style.title">実績</h2>
<ul v-if="contests.length > 0" :class="$style.contests">
<li v-for="contest in contests" :key="contest.id" :class="$style.contest">
<router-link :to="`/contests/${contest.id}`" :class="$style.link">
<router-link
:to="{ name: 'Contest', params: { contestId: contest.id } }"
:class="$style.link"
>
<h4>{{ contest.name }}</h4>
<div
v-for="team in contest.teams"
Expand Down
5 changes: 2 additions & 3 deletions src/lib/param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const toStringIfArray = (s: string | undefined | readonly string[]) =>
Array.isArray(s) ? s[0] : s

/**
* @param paramName - 取得するparam、存在しないものを取得しようとした場合、undefinedが返るので注意
* @param paramName - 取得するparam、存在しないものを取得しようとした場合、'undefined'が返るので注意
*/
const useParam = (paramName: string): ComputedRef<string> => {
const route = useRoute()
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return computed(() => toStringIfArray(route.params[paramName])!)
return computed(() => toStringIfArray(route.params[paramName]) ?? 'undefined')
}

export default useParam
4 changes: 2 additions & 2 deletions src/pages/ContestPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ onMounted(() => {
<template>
<page-container
:paths="[
{ name: 'Contests', link: '/contests' },
{ name: 'Contests', link: { name: 'Contests' } },
{
name: contestDetail.name,
link: `/contests/${contestId}`
link: { name: 'Contest', params: { contestId: contestId } }
}
]"
>
Expand Down
9 changes: 6 additions & 3 deletions src/pages/ContestTeamPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ onMounted(() => {
<template>
<page-container
:paths="[
{ name: 'Contests', link: '/contests' },
{ name: 'Contests', link: { name: 'Contests' } },
{
name: contestDetail.name,
link: `/contests/${contestId}`
link: { name: 'Contest', params: { contestId: contestId } }
},
{
name: contestTeamDetail.name,
link: `/contests/${contestId}/teams/${teamId}`
link: {
name: 'ContestTeam',
params: { contestId: contestId, teamId: teamId }
}
}
]"
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ContestsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ onMounted(() => {
</script>

<template>
<page-container :paths="[{ name: 'Contests', link: '/contests' }]">
<page-container :paths="[{ name: 'Contests', link: { name: 'Contests' } }]">
<div :class="$style.container">
<page-title>コンテスト一覧</page-title>
<contest-list :contests="contests" />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/GroupPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ onMounted(() => {
<template>
<page-container
:paths="[
{ name: 'Groups', link: '/groups' },
{ name: 'Groups', link: { name: 'Groups' } },
{
name: groupDetail.name,
link: `/groups/${groupId}`
link: { name: 'Group', params: { groupId: groupId } }
}
]"
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/GroupsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ onMounted(() => {
</script>

<template>
<page-container :paths="[{ name: 'Groups', link: '/groups' }]">
<page-container :paths="[{ name: 'Groups', link: { name: 'Groups' } }]">
<div :class="$style.container">
<page-title>班一覧</page-title>
<group-list :groups="groups" />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/ProjectPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ onMounted(() => {
<template>
<page-container
:paths="[
{ name: 'Projects', link: '/projects' },
{ name: 'Projects', link: { name: 'Projects' } },
{
name: projectDetail.name,
link: `/projects/${projectId}`
link: { name: 'Project', params: { projectId: projectId } }
}
]"
>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProjectsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ onMounted(() => {
</script>

<template>
<page-container :paths="[{ name: 'Projects', link: '/projects' }]">
<page-container :paths="[{ name: 'Projects', link: { name: 'Projects' } }]">
<div :class="$style.container">
<page-title>プロジェクト一覧</page-title>
<project-list :projects="projects" />
Expand Down
4 changes: 2 additions & 2 deletions src/pages/UserPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ onMounted(() => {
<template>
<page-container
:paths="[
{ name: 'Users', link: '/users' },
{ name: 'Users', link: { name: 'UserSearch' } },
{
name: userDetail.name,
link: `/users/${userId}`
link: { name: 'User', params: { userId: userId } }
}
]"
>
Expand Down

0 comments on commit d6ab9cc

Please sign in to comment.