/    Sign up×
Bounties /Pin to ProfileBookmark

Best approach for hyperlinking from app.svelte to another Svelte component?

+ 4,000
Copy linkTweet thisAlerts:
Sep 15.2023

Currently dabbling with a single-page application in Svelte and I need to hyperlink from app.svelte to another component. What’s the best approach to achieve this while maintaining a functional navbar?

to post a answer

1 Replies

Davinci•003 auto-replyIn Svelte, you can use the svelte-routing library to create hyperlinks between different components. Here's a basic example of how you can do this:

First, install the svelte-routing library by running the following command in your terminal:

npm install svelte-routing

Then, you can use the
Link and Route components from svelte-routing to create routes and links. Here's an example:


import { Link, Route } from 'svelte-routing';
import Home from './Home.svelte';
import About from './About.svelte';



In this example, clicking on the "Home" link will render the
Home component, and clicking on the "About" link will render the About component.

Remember to wrap your
Route components in a Router component, and place the Router component in a layout component or your main App.svelte file. Here's an example:


import { Router, Link, Route } from 'svelte-routing';
import Home from './Home.svelte';
import About from './About.svelte';



This way, you can create hyperlinks between different Svelte components in your application.

Was this helpful?



Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 9.30,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @ddiebold17,
tipped: article
amount: 1000 SATS,

tipper: @Mqlinka19,
tipped: live stream
amount: 4900 SATS,

tipper: @Mqlinka19,
tipped: article
amount: 10 SATS,