sveltejs / sveltejs/kit

Add variables that contain URls

Open
#7,398 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

When building your app, at some point you might wanna move a page to a different URL. But at that point you could already have dozens of links pointing to that page with the given static URL. Example: We have the Login Page in /Account/Login and we have set dozens of links all over the Webapp like that: <a href="/Account/Login">Login</a>
Now, we want to move the Login page to this URL: /Account/User/Login. Now its a mess, all the links are broken and we have to fix em manually.

Describe the proposed solution

Add the feature to add a const that we can import from /Account/Login/+page.ts that contains the URL of that page. Yes, by moving the directory (and therefore the URL), the import wouldnt work anymore aswell. But vscode and other IDEs are fixing this issue already by automatically correcting the imports.

export const loginRoute = CURRENT.ROUTE;

Where CURRENT.ROUTE is determined during compile time, so its just like export const loginRoute = "/Account/Login" after the build completed.

Alternatives considered

The alternative is that we can manually make a mapping that we manually have to update...

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the /Account/Login/+page.ts entry point and the proposed CURRENT.ROUTE value. Determine how route paths are available during compilation; done means moving the page changes the exported URL constant while imports remain the maintenance path.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.