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

Specifying a route Transition from / to any URL doesn’t use that Transition #29

Open
xdesro opened this issue Dec 21, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@xdesro
Copy link

xdesro commented Dec 21, 2024

Hey mate, bet you thought you'd seen the last of me :D If it turns out I was just misunderstanding the docs, I sincerely apologize :)

Describe the bug
I have a basic Taxi setup which uses the following code to set a transition from the homepage to another route:

const taxi = new Core({
  transitions: {
    default: DefaultTransition,
    homeToWork: HomeToWorkTransition,
  }
});
taxi.addRoute('/', '/work', 'homeToWork');

But when accessing that route by clicking a link from my homepage to the /work page, the DefaultTransition is used instead.

To Reproduce
I created a minimal demo repo that shows this in action, using Taxi 1.8.0, and includes the (as always) extremely hacky patch I used to get my local project running again. -> https://github.com/xdesro/taxi-demo-router

Info
If applicable, add screenshots to help explain your problem.

  • Device: 2023 MacBook Pro
  • OS: OS X Sequoia 15.1
  • Browser: Firefox 133 and Chrome 131
@xdesro xdesro added the bug Something isn't working label Dec 21, 2024
@jakewhiteley
Copy link
Member

Hi @xdesro,

sorry about the massive wait on this one. I have time this weekend, so will investigate for you.

@jakewhiteley
Copy link
Member

Hi @xdesro ,

So if the current URL has a trailing slash, then the window.location.pathname will also have a trailing slash, and the same is true if the slash is missing.

Although common to redirect to a canonical version, it is not as common as you might think (for instance the URL of this issue can be accessed at #29 and #29 with no redirect).

So when making taxi I knew this would be annoying, and that the pathnames should be normalised. I had a choice to remove the slash or enforce it, and removing it felt safer but it was ultimately a coin toss as to which won.

So the solution to your issue is either do this:

taxi.addRoute('', '/work', 'homeToWork');

or this:

taxi.addRoute('/?', '/work/?', 'homeToWork');

I will add the fact that all Taxi routes have trailing slashed removed into the docs.

@jakewhiteley
Copy link
Member

This was introduced not too long ago actually, and was the breaking change which bumped the library from 1.7.* to 1.8.

My memory on it is bad, but I believe this change was needed to better handle anchor link popstate changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants