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

href inside +layout.svelte always relative to current url, not the file route #10708

Closed
risalfajar opened this issue Sep 12, 2023 · 3 comments
Closed

Comments

@risalfajar
Copy link

risalfajar commented Sep 12, 2023

Describe the bug

My routes structure is like this

/routes
  /dashboard
    /programs
      /inventory
      /investment
      +layout.svelte

Inside +layout.svelte I have a tabbed layout using anchors

	<div class="tab-group">
		<a href="inventory">INVENTORY</a>
		<a href="investment">INVESTMENT</a>
	</div>
	<slot />

Clicking the tab works for the first time, it goes to /dashboard/programs/inventory/, but when I click the same tab again it will go to /dashboard/programs/inventory/inventory/ which is 404.

trailingSlashes is set to “always”, other values won't work.

How to fix this without using absolute path?

Reproduction

Repo

Logs

No response

System Info

System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M2
    Memory: 62.81 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.0 - ~/.nvm/versions/node/v18.17.0/bin/node
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.0/bin/npm
  Browsers:
    Safari: 16.6
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.0 
    @sveltejs/kit: ^1.20.4 => 1.24.1 
    svelte: ^4.0.5 => 4.2.0 
    vite: ^4.4.2 => 4.4.9

Severity

annoyance

Additional Information

No response

@Conduitry
Copy link
Member

You need to construct the appropriate URLs yourself. There's no concept in HTML of a base URL just for a part of a page, and we don't want to take URL resolution out of the hands of the browser, or rewrite hrefs on the fly, etc. The current behavior is the intended behavior.

@Conduitry Conduitry closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2023
@risalfajar
Copy link
Author

I believe this is related to this, but I can't find the solution.

Is there no way to get the path of the file (not the current route, as in $page.route or $page.url)? So that we can prepend it in the href.

I think it'll be very useful for deep nested routes, especially if it has lots of slug.
This is an example from other project:

<li class="crumb"><a href="/dashboard/projects/{$company.id}/{year}/{month}/{$project.id}/items">{$project.name}</a></li>

@risalfajar
Copy link
Author

risalfajar commented Sep 12, 2023

Maybe we can introduce url() like in Routify?

It has been requested before in #822

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

No branches or pull requests

2 participants