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

params.splat being coerced to string before creating URL with transitionTo #317

Closed
appsforartists opened this issue Sep 26, 2014 · 3 comments

Comments

@appsforartists
Copy link

I have a transitionTo call that looks like this:

ReactRouter.transitionTo(
  "example",
  {
    "keyName":    keyName,
    "splat":      ["grandpa", "mom", "me"]
  }
);

which calls this route:

<Route
  path    = "/example/:keyName/*/"

I expect a URL that looks like this:

http://localhost:8080/example/4025675/grandpa/mom/me/

Instead, I see this:

http://localhost:8080/example/4025675/grandpa%2Cmom%2Cme/

I suspect the array is being toStringed before processing.

@appsforartists
Copy link
Author

I've been using an old fork of ReactRouter in order to support server-rendering until #181/#261 land. This bug has changed in the latest versions of RR.

Now, instead of getting

http://localhost:8080/example/4025675/grandpa/mom/me/

I'm seeing

http://localhost:8080/example/4025675/grandpa/

To get the full path, I'd either have to put the precise number of *s in the URL (which is impossible when it's dynamically-generated) or .join('/') the splat before passing it in. Likewise, path = "/*/" now gives you a single string "grandpa/mom/me" if you use a single *.

So, as a workaround (or perhaps intended behavior), I can use .join("/"). Based on the previous implementation, I would have expected this to result in grandpa%2Fmom%2Fme, but this does not seem to be the current behavior.

@mjackson / @rpflorence, what's the intended behavior here? If .join is the right solution, we should update the docs accordingly. If not, but you wish to keep the current splat-indexing, perhaps another token (like **) could denote a greedy splat.

@ryanflorence
Copy link
Member

With a route like this:

<Route path="/example/:keyName/*/" />

It should just be:

ReactRouter.transitionTo("example", {
    "keyName":    keyName,
    "splat":      "grandpa/mom/me"
});

If you had three splats like this:

<Route path    = "/example/:keyName/*/*/*/" />

Then you'd send an array like in your example.

I added another test to show this behavior ca5d813

If I'm misunderstanding, please let me know and I'll reopen. But if you only have one splat, don't send an array of splat values, just send one value :)

@appsforartists
Copy link
Author

Thanks for the clarification. 😃

@lock lock bot locked as resolved and limited conversation to collaborators Jan 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants