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

Prefix all route IDs with / #7332

Closed
Rich-Harris opened this issue Oct 20, 2022 · 3 comments · Fixed by #7338
Closed

Prefix all route IDs with / #7332

Rich-Harris opened this issue Oct 20, 2022 · 3 comments · Fixed by #7338

Comments

@Rich-Harris
Copy link
Member

Describe the problem

I don't recall if there was a reason we decided that the routeId for src/routes/foo/+page.svelte should be foo instead of /foo, but I think it was a mistake. On a number of occasions I've found myself doing things like if (routeId) and getting caught out because it can sometimes be the empty string.

Since we expose routeId via event, app developers will inevitably run into the same issue.

Describe the proposed solution

It would be safer, and arguably more intuitive, if route IDs were always prefixed with /.

Alternatives considered

The problem of course is that this would be a breaking change, and we can't detect people doing routeId === 'foo'. For the people currently using routeId this would be annoying.

The question is whether causing breaking change for that population is more costly than reaching 1.0 with a known design flaw.

Importance

would make my life easier

Additional Information

No response

@dummdidumm
Copy link
Member

On way to ease this for users would be to detect that routeId is accessed and print a warning once per dev session that this was changed.

@Conduitry
Copy link
Member

I'm in favor of this change. The path portion of URLs always including the leading / is something everyone's fairly used to by now, and the empty string falsy exception is something that's nice to be able to avoid.

I suppose I'm ambivalent about the dev time warning, because for each person it sounds like that will either be (a) something they never look at, or (b) something that irritates them when it's printed every time, even after they've made the appropriate changes.

Rich-Harris added a commit that referenced this issue Oct 21, 2022
* prefix all route IDs with / - closes #7332

* expected prefix

Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>
@jfreyberg
Copy link

It seems $page.routeId is now $page.route.id. I was wondering why $page.routeId is undefined and found this thread so I'm leaving this comment here.

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

Successfully merging a pull request may close this issue.

4 participants