Svelte Way is small SPA router for Svelte 3. Inspired by React Router.
via npm: npm install svelte-way
or via yarn: yarn add svelte-way
.
Main component for routing. Childs are rendered if route prop path match url.
path
route url structure with following format /some-route/:param_name/
(string).exact
if true route will match only exact url as provided in the path prop. (boolean, default: false).params
object that contains params as defined in path route prop (object).<Route path="/home">
<h1>Home</h1>
</Route>
<Route path="/user/:id" let:params>
<h1>User #{params.id}</h1>
</Route>
Component for navigation links.
path
url to link to (string).activeClass
class for active state (string, default: active).<Link path="/home">Home</Link>
After mount redirect component will redirect to the specified path.
path
url to redirect to (string).<Route exact path="/home">
<Redirect path="/" />
</Rout
Renders the first Route component that matches URL.
<Switch>
<Route exact path="/">
<h1>Home</h1>
</Route>
<Route exact path="/home">
<Redirect path="/" />
</Route>
<Route exact path="/about">
<h1>About</h1>
</Route>
<Route exact path="/user/:id" let:params>
<h1>User with id: #{params.id}</h1>
</Route>
<Route exact path="/user/:id/:section" let:params>
<h1>User with id: #{params.id} -> {params.section}</h1>
</Route>
<Route>
<h1>404</h1>
</Route>
</Switch>