Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support mixing dynamic params with static string in same segment #11

Closed
SilentDepth opened this issue Sep 28, 2022 · 2 comments · Fixed by #52
Closed

Support mixing dynamic params with static string in same segment #11

SilentDepth opened this issue Sep 28, 2022 · 2 comments · Fixed by #52

Comments

@SilentDepth
Copy link

Repro

https://runkit.com/silentdepth/633470604bb52500089af4de

Issue

One

  • /:msg
  • /:msg.txt

The current version sees these 2 patterns as the same, and the second will overrides the first. However, they should be different.

Two

  • /:msg.txt
  • /:msg/uppercase.txt

Just not sure how these work... The result confuses me.

Versions

Node: 16.17.0
radix3: 0.1.2

@pi0 pi0 changed the title Unexpected result when param name contains dot Support mixing dynamic params with static string in same segment Oct 13, 2022
@pi0
Copy link
Member

pi0 commented Oct 13, 2022

Hi @SilentDepth and thanks for repro and explaining. The issue you are facing is that .txt is becoming part of the param name as you can see in the output it is params: Object {msg.txt: "something"}.

Currently, radix 3 does not allow combining a param name with some static prefix and/or suffix in the same segment like /foo/prefix-:param-suffix.

@lihbr
Copy link
Member

lihbr commented Jan 8, 2023

Hey there, just chiming in with a temporary workaround for this issue/out-of-scope request

I managed to support file extensions routing by transforming routes before resolving them, something in that fashion if that makes sense (simplified for clarity purpose):

import { createRouter } from "radix3";

const router = createRouter();

router.insert("/foo/:msg/dot/txt");

router.lookup("/foo/something.txt".replace(".", "/dot/"));

It's limited, and suboptimal, but it ain't stupid if it works ^^'

I'm curious however if this is out-of-scope for radix 3 or what are the plans, if any, to either support something like that or supporting/replacing colon-based parameters (:slug) with square brackets-based parameters ([slug])?

Happy to help~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants