Skip to content

useParam() doesn't return a parameter if the value of it starts with a hash while using the HashRouter #460

@MTRNord

Description

@MTRNord

Describe the bug

I have this route setup currentlly:

<HashRouter>
        <Route path="/:roomId?" component={App} matchFilters={{
            roomId: /^(!|\$|#)/ // Match $ or # for the roomId
        }} />
        <Route path="/login" component={Login} />
</HashRouter>

Using http://localhost:5173/#/$test works, using http://localhost:5173/#/!test works but using http://localhost:5173/#/#test causes the roomId param to be undefined when using it.

Example usage is:

export default function App() {
    const params = useParams();

    return (
        <ErrorBoundary fallback={(err) => <div>Error: {err.message}</div>}>
            <div class="wrapper">
                <Show when={params.roomId} fallback={<p>No Room</p>} keyed>
                    <p>room</p>
                </Show>

            </div>
        </ErrorBoundary>
    )
}

Your Example Website or App

See the above for a minimal example of the issue.

Steps to Reproduce the Bug or Issue

See above for a minimal example of the issue and how to reproduce it please.

Expected behavior

I would expect that #test is equally valid as any other string and isnt omitted.

Screenshots or Videos

No response

Platform

  • OS: Linux Fedora 40
  • Browser: Firefox 128.0 (64-Bit)
  • Version: SolidJs ^1.8.18 | Solidjs-Router ^0.14.1

Additional context

I haven't checked the other routers as my app isnt SSR compatible

Metadata

Metadata

Assignees

No one assigned

    Labels

    pr welcomeGladly accept a PR for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions