/    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
Front-endSvelte

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:

``bash
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:

`svelte

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



Home
About




`

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:

`svelte

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




Home
About





``

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

Was this helpful?

×

Success!

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 5.11,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...