Skip to content

Commit

Permalink
fix project wild card route not parsing query param properly (supabas…
Browse files Browse the repository at this point in the history
…e#18268)

* fix project wild card route not parsing query param properly

* Update based on feedback

* Add ts ignore

* address comments
  • Loading branch information
joshenlim authored Oct 18, 2023
1 parent 4d1fd58 commit 6d192a1
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions studio/pages/project/_/[[...routeSlug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,21 @@ const Header = () => {
const GenericProjectPage: NextPage = () => {
const router = useRouter()
const { routeSlug, ...queryParams } = router.query
const queryString =
Object.keys(queryParams).length > 0
? new URLSearchParams(queryParams as Record<string, string>).toString()
: ''

const query = Object.keys(queryParams).length
? `?${new URLSearchParams(queryParams as Record<string, string>)}`
: undefined

const urlRewriterFactory = (slug: string | string[] | undefined) => {
return (projectRef: string) => {
const hash = location.hash
const hash = location.hash ? `#${location.hash}` : undefined

if (!Array.isArray(slug)) {
return [`/project/${projectRef}`, queryString ?? `?${queryString}`, hash ?? `#${hash}`]
.filter(Boolean)
.join('')
return [`/project/${projectRef}`, query, hash].filter(Boolean).join('')
}

const slugPath = slug.reduce((a, b) => `${a}/${b}`, '').slice(1)
return [
`/project/${projectRef}/${slugPath}`,
queryString ?? `?${queryString}`,
hash ?? `#${hash}`,
]
.filter(Boolean)
.join('')
return [`/project/${projectRef}/${slugPath}`, query, hash].filter(Boolean).join('')
}
}

Expand Down

0 comments on commit 6d192a1

Please sign in to comment.