Giter VIP home page Giter VIP logo

svero's Introduction

⚠️⚠️ THIS LIBRARY IS DEPRECATED AND SHOULD NOT BE USED IN NEW PROJECTS ⚠️⚠️

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

⚠️⚠️ MORE DETAILS HERE. ⚠️⚠️

⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️
⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️⚠️

npm version Build Status

svero (Svelte Router): A simple router for Svelte 3.

First things first

svero is intented to be used in SPA (Single Page Applications) making usage of pushState and History API. We're assuming that you already know how to configure your front-end server (being it dev or production) to serve all path requests to index.html.

If you're not familiar with the terms SPA, pushState or History API, you should probably be reading these first:

http://krasimirtsonev.com/blog/article/deep-dive-into-client-side-routing-navigo-pushstate-hash
https://css-tricks.com/using-the-html5-history-api/
https://diveinto.html5doctor.com/history.html
https://developer.mozilla.org/pt-BR/docs/Web/API/History

Installation

Since it's exported in CommonJS format, you should be using it with a module bundler such as Rollup or Webpack.

You can install svero via npm:

npm install --save svero

Usage

The usage is super simple:

<!-- ./App.svelte -->
<script>
  import { Router, Route } from 'svero';

  import Index from './pages/Index.svelte';
  import About from './pages/About.svelte';
  import Employees from './pages/Employees.svelte';

  let employees = [{ id: 1, name: 'Bill'}, { id:2, name: 'Sven' }];
</script>

<Router>
  <Route path="*" component={Index} />
  <Route path="/about" component={About} />
  <Route path="/about/:who/123/:where" component={About} />
  <Route path="/employees">
    <Employees {employees}/>
  </Route>
</Router>

The * wildcard simply works as a fallback. If a route fails to meet any other path, it then loads the path with the *. If there is no wildcard route and the route did not meet any other path, nothing is loaded.

Your custom props can be passed by putting your component in the Route slot (Employees example above).

Paths with parameters (:param) are passed to components via props: router.params.

Parameters like *param will capture the rest of segments. You can access them as router.params._ like other params.

A component loaded by <Route> receives a property with route details:

<!-- ./pages/About.svelte -->
<script>
  export let router = {};

  // Those contains useful information about current route status
  router.path; // /test
  router.route; // Route Object
  router.params; // /about/bill/123/kansas { who: 'bill', where: 'kansas' }
</script>

Additional properties are passed to the mounted component, e.g.

<Route component={Test} title="Some description" />

Also, you can pass an object:

<Route component={Test} props={myProps} />

Route props are omitted, but all remaining ones are passed to Test.

Routes can also render any given markup when they're active, e.g.

<Route path="/static-path">
  <h1>It works!</h1>
</Route>

You can access router within <slot /> renders by declaring let:router on <Router /> or <Route /> components (see below).

If you're building an SPA or simply want to leverage on hash-based routing for certain components try the following:

<Route path="#g/:gistId/*filePath" let:router>
  <p>Info: {JSON.stringify(router.params)}</p>
</Route>

Standard anchors and <Link /> components will work as usual:

<a href="#g/1acf21/path/to/README.md">View README.md</a>

Declaring a component <Route path="#" /> will serve as fallback when location.hash is empty.

Nesting

You can render svero components inside anything, e.g.

<Router nofallback path="/sub">
  <Route>
    <fieldset>
      <legend>Routing:</legend>
      <Router nofallback path="/sub/:bar">
        <Route let:router>{router.params.bar}!</Route>
      </Router>
      <Route path="/foo">Foo</Route>
      <Route fallback path="*" let:router>
        <summary>
          <p>Not found: {router.params._}</p>
          <details>{router.failure}</details>
        </summary>
      </Route>
      <Router nofallback path="/sub/nested">
        <Route>
          [...]
          <Route fallback path="*">not found?</Route>
          <Route path="/a">A</Route>
          <Route path="/b/:c">C</Route>
          <Route path="/:value" let:router>{JSON.stringify(router.params)}</Route>
        </Route>
      </Router>
    </fieldset>
  </Route>
</Router>

Properties determine how routing will match and render routes:

  • Use the nofallback prop for telling <Router /> to disable the fallback mechanism by default
  • Any route using the fallback prop will catch unmatched routes or potential look-up errors
  • Use the exact prop to skip this route from render just in case it does not matches
  • A <Route /> without path will render only if <Router path="..." /> is active!

Note that all <Router /> paths MUST begin from the root as /sub and /sub/nested in the example.

Redirects

Sometimes you just want a route to send user to another place. You can use the redirect attribute for that.

A redirect should always be a string with a path. It uses the same pattern as path attribute. For a redirect to run, there must be a Route with the equivalent path.

<Router>
  <Route path="/company" redirect="/about-us">
  <Route path="/about-us" component={AboutUs}>
</Router>

Conditions

If you need to meet a condition in order to run a route, you can use the condition attribute. Conditions can also be used with redirect for graceful route fallback.

A condition should be either boolean or a function returning boolean. There is no support for asynchronous conditions at the moment (so keep it simple).

<Router>
  <Route path="/admin/settings" condition={isAdminLogged} redirect="/admin/login">
</Router>

Think of it as a simpler middleware. A condition will run before the route loads your component, so there is no wasteful component mounting, and no screen blinking the unwanted view.

Link Component

There is also an useful <Link> component that overrides <a> elements:

<Link href="path/here" className="btn">Hello!</Link>

The difference between <Link> and <a> is that it uses pushState whenever possible, with fallback to <a> behavior. This means that when you use <Link>, svero can update the view based on your URL trigger, without reloading the entire page.

Given href values will be normalized (on-click) if they don't start with a slash, e.g. when location.pathname === '/foo' then #bar would become /foo#bar as result.

navigateTo()

In some cases you want to navigate to routes programatically instead of letting user click on links. For this scenario we have navigateto() which takes a route as parameter and navigates imediatelly to said route.

navigateTo() receives the same treatment as <Link>: It will always try to use pushState for better performance, fallbacking to a full page redirect if it isn't supported.

Usage:

<script>
  import { onMount } from 'svelte';
  import { navigateTo } from 'svero';

  onMount(() => {
    if (localStorage.getItem('logged')) {
      navigateTo('/admin');
    }
  });
</script>

Webpack issues

If you're having trouble with Webpack failing to load svero, please replace the following rule (in Svelte rule):

exclude: /node_modules/,

with:

exclude: /node_modules\/(?!(svero)\/).*/,

More information here.

svero's People

Contributors

almoullim avatar coconuttheslayer avatar dependabot[bot] avatar kazzkiq avatar n1313 avatar pateketrueke avatar tehpsalmist avatar tomkersten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

svero's Issues

className ?

Why'd you choose to use className instead of just class? It looks really inconstant.

path="*": it doesn't react to path changes.

I'm using the following:

<Route fallback path="*" component={Page} />

To send routes to the Page component that will lookup the path and see if there is a corresponding markdown file. If there is, it renders it. But, the Page component isn't getting anything when I go to one page and then another that would match it. If I go the a page that is a different component with it's own path, it changes fine. But, going from two pages that would match the above rule does absolutely nothing.

New to Svelte: How would you setup this situation?

Hey, found your router solution as I'm messing around with Svelte 3.

Let's say we need this.

Route "/" to load Main
Route "/foo" to load Foo.svelte which imports Baz.svelte
Route "/bar" to load Bar which also imports the same Baz.svelte

Now my naive approach just did it as is but this is the issue.
Baz.svelte has onMount that does a thing.
Because the router remounts the whole component, it remounts the children too.
If I take the Baz.svelte outside of the Foo and Bar and into the App.svelte outside of router, I avoid the rerenders but now it also shows on "/" which is not what I wanted.

Can you point me in the right direction?

On component destroy routes with params leads to uncaught exception in promise

Example:

<script>
	import { Router, Route } from 'svero'
	
	let flag = true;
</script>

{#if flag}
<Router>
	<Route path="/">123</Route>
	<Route path="/A">234</Route>
	<Route path="/A/:param">345</Route>
</Router>
{/if}

<button on:click="{() => flag = false}">
	test
</button>

After clicking on button it throws uncaught exception in promise:

defaultExport {message: "Unreachable '/A/:param', segment '/A' is not defined"}

Svero is being deprecated.

It's been about a year since the first release of Svero.

Svelte 3 was a brand new technology back then. There were not much dedicated routers (if any). Svero came out of necessity at the time, and now this necessity is no more. Svelte grew in popularity (thanks to the awesome contributors and JavaScript jedi Rich Harris) and lots of router libraries came to life.

Meanwhile my free time got more and more scarce to the point I couldn't even work on Svero 2.0, which should have it's birth months ago.

Due do work schedule and prospects, I do not think there will be much time left in the near future to work on this lib, so I decided to deprecate Svero and officially stop with it's development.

It's a hard decision. I've never deprecated any OS project before, but as of today I see Svero doing more harm than good as newcomers keep coming, staring the project, trying to use it, and failing miserably because it's not being actively maintained.

I recommend those who use Svero to switch to other solutions as soon as possible. I will link alternatives in the bottom of this issue.

If you already use Svero and cannot migrate to other router at the moment, there is no need to worry. This repo will stay public, forks are encouraged, and current npm releases will always be available. Nothing will be deleted, it just won't be updated, fixed or have any more releases.

Here are some alternatives to Svero:

Problem with exact prop on <Route/>

I don't think exact pathing is working as expected.

Given the following routes from App.svelte, I would expect /stooges to render the <Stooges/> component and /stooges/add to only render the <AddStooges/> component. Instead it renders both <Stooges/> and <AddStooges/>.

Further more, I would expect that /stooges/non-existent would only render <h1>404 - Not Found</h1> but it also renders <Stooges/>.

<Router>

	<!-- <Route exact path='/stooges/add' component={AddStooge}/> -->
	<Route exact path='/stooges' component={Stooges}/>
	<Route exact path='/stooges/add' component={AddStooge}/>
	
	<Route fallback path='*'>
		<h1>404 - Not Found</h1>
	</Route>

</Router>

Unless I'm missing something? I have an example at this repo.

EDIT: I've add a svelte-routing branch which demo's the expected behavior.

Svero is picking the wrong component

With this code:

<Router>
  <Route path="/game/parties/:party_id" component={Party} />
  <Route path="/game/new-party" component={PartyCreate} />
  <Route path="/game" component={Dashboard} />
</Router>

When I load the page as /game, the Party component is initialized (with undefined as party_id.

resolveRoutes returns:

[
  {
    "matches": true,
    "params": {},
    "route": "/",
    "path": "/"
  },
  {
    "matches": false,
    "params": {},
    "route": "/",
    "path": "/"
  },
  {
    "key": "p23gll8y2o",
    "matches": true,
    "params": {},
    "route": "/game",
    "path": "/game"
  }
]

I know I can use a basePath for the moment, but I may have urls not starting with /game to handle.

What did I do wrong ?

Simple example throws "unassignRoute is not a function"

I'm trying with some simple example from README but on accessing the page I get and error

TypeError: unassignRoute is not a function
    at onDestroy (/Users/uros/Sites/svelte-svero/example/public/App.js:812:5)
    at run (/Users/uros/Sites/svelte-svero/example/public/App.js:4:9)
    at Array.forEach (<anonymous>)
    at run_all (/Users/uros/Sites/svelte-svero/example/public/App.js:12:6)
    at Object.render (/Users/uros/Sites/svelte-svero/example/public/App.js:83:4)
    at /Users/uros/Sites/svelte-svero/example/server.js:10:24
    at Layer.handle [as handle_request] (/Users/uros/Sites/svelte-svero/example/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/uros/Sites/svelte-svero/example/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/uros/Sites/svelte-svero/example/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/uros/Sites/svelte-svero/example/node_modules/express/lib/router/layer.js:95:5)

Incompatibility with latest version of Svelte(3.14.1)

To reproduce this bug, use npx degit sveltejs/template to use the latest version of Svelte with svero.

The following lines from Route.svelte was causing an error:

  $: {
    activeRouter = $routeInfo[key];
    activeProps = getProps($$props, arguments[0]['$$'].props);
  }

as arguments[0]['$$'].props was in fact an object type after several updates from Svelte.

However, on the same source, Array.prototype.forEach is used to iterate through the second argument of getProps function, so the resulting error would show that the function does not exist.

To fix, replace the line with the following or

  $: {
    activeRouter = $routeInfo[key];
    activeProps = getProps($$props, Object.keys(arguments[0]['$$'].props));
  }

add the following line within the getProps function to allow for backward compatibility.

  // prune all declared props from this component
  required = (typeof required === 'object' ? Object.keys(required) : required);
  required.forEach(k => {
    delete others[k];
  });

I've made this fix in my fork, which takes the former approach. I'd suggest the master branch to go with the latter if backward compatibility is preferred. Please look into this! Thank you.

Link class undefined

Now using:

<Link href="/">Home</Link>

becomes:

<a href="/" class="undefined">Home</a>

Is it correct?

"svelte": "3.2.2",
"svero": "0.4.0"

Support for hash-based history

Any plans to implement support for "hash-based" history, e.g. without using the HTML5 history API?

The use case is that the app I'm working on is fully static and not a PWA. I cannot use the history API as the underlying pages don't really exist.

Listen to query string changes

So, I have a search route that takes the current query string on mount and fetches some data, but when I update the query string using navigateTo it does not triggers a re-render. How can I handle this kind of updates? If I use afterUpdate or lifecycle methods it would create an endless loop of fetch requests.

Is there support for handling query string?

Svero doesn't seem to support automatically parsing and adding query string into router object. With the support, loading https://github.com/kazzkiq/svero/issues/new?foo=bar would add "foo": "bar" somewhere in the router.

It's a bit annoying to implement along with fragment based routing, but it could be handy!

store.subscribe is not a function

The moment I add this to my App.svelte:

  <Router>
    <Route exact path="/" component={Products} />
  </Router>

This error is being thrown: store.subscribe is not a function. I have not digg deep to check the source of the problem and tend to ask first if anyone had this before. Otherwise I must be skeptical about the source code of svero.

Lazy loading routes and router hooks

Lazy loading is very important for bundle size. Does Svero supports lazy route loading? How can I display a progress bar during route loading? Is there any plan to add router hooks?

Nested routes?

Could you please add an example how to use nested routes?

Condition middle-ware

Condition middle-ware is not working, the router doesn't redirect to the given route.

Blank page. No hope

I am totally unable to load page. I've followed your tutorial for 3 times and also watched a video tutorial by Garry Simon but nothing working in my case.
Following guideline, I created 3 pages in pages folder. I used export let router = {}; router.path; router.route; router.params; props in each page and using Link tag I made anchors but when I add Router and Route the content on the page disappears.
Look nothing here. (ignore that little box)
Kazam_screenshot_00007
my code now
Kazam_screenshot_00000
but when I just hide Router things appear on browser like I commented router below
Kazam_screenshot_00009
and see header and h1 content came on page
Kazam_screenshot_00008

"'watchQuery' of undefined" error using a routing solution. Maybe we need to wait "setClient(client)"?

I think I found a bug.

I still don't know if the bug is caused by svelte-apollo (https://github.com/timhall/svelte-apollo/) or what I'm using for routing in this project: svero.

PROBLEM REPRODUCTION: https://codesandbox.io/s/bzix3

In codesandbox there are still some problems with Svelte (or maybe I'm the problem) but it doesn't work. You have to download it and run with: npm i && npm run dev.

THE PROBLEM:

If I go to http://localhost:5000/ the Home Page is correctly displayed.

If I go to http://localhost:5000/articles USING THE LINK!!! the Articles Page is correctly displayed.

If now I reload the page I get this error in browser console:

svelte-apollo.es.js:51 Uncaught TypeError: Cannot read property 'watchQuery' of undefined
    at query (svelte-apollo.es.js:51)
    at instance$3 (ArticlesPage.svelte:14)
    at init (internal.mjs:1395)
    at new ArticlesPage (ArticlesPage.svelte:14)
    at updateComponent (Router.svelte:24)
    at handleRoute (Router.svelte:65)
    at Router.svelte:76
    at Array.some (<anonymous>)
    at handlePopState (Router.svelte:70)

If I use console.log(client) just after ArticlesPage.svelte line 13 (const client = getClient();) I can see the client is indeed undefined.

Maybe we have to wait for setClient(client) in the App.svelte file to finish is job?

Wildcard and redirect don't seem to work together

Redirect routes work fine with a path, but not for wildcard routes:

<Router>
  <Route path="*" redirect="/version" />
  <Route path="/about" component={About} />
  <Route path="/version" component={Version} />
  <Route path="/another" redirect="/version" />
</Router>

I would have expected that when hitting the "/" url, to be redirected to "/version" but it just doesn't do anything. When hitting "/another" I get correctly redirected to "/version".

Thoughts on Svero 2.0

When I first drafted this project, there were almost no Svelte-based routes around. Svelte 3 was brand new, and I felt the need to have an easy, lean and simple way to actually handle routes using Svelte own component's syntax.

It's been some time now and there are plenty of Svelte-based route projects around. Some focusing on speed, others on bundle size, and others on having lot's of features and complexity. Meanwhile, it seems to me that Svero tried to embrace every aspect of a successful router, aiming at all sides, but barely hitting any.

That being said, I believe it's time to define the future of Svero and it's 2.0 version, and this is what I think it should not be:

  1. Svero should not be a Svelte equivalent to react-router;
  2. Svero should not be bounded by react-router API/nomenclatures;
  3. Svero should not focus on advanced router features (nesting, super-crazy regex routes, hash subroutes, etc).

What I think Svero should be:

  1. A simple and reliable library for routing in Svelte 3;
  2. As lean and small as possible without having to opt-out of Svelte syntax;
  3. Something focused for projects without advanced and fancy routing requirements.

With all that being said, I will start working on the new 2.0 version that may end up dropping some features, adding others, and making the library simpler, smaller and reliable. For those who feel the need to use something more robust, here is a list of alternatives:

Wildcard route declared last catches all routes

I am trying to setup a configuration where URLs with no matching route would display a NotFoundPage component. It looks like the wildcard route should help me achieve this, but I find its behaviour confusing.

The following setup displays NotFoundPage for pathname / (and for every other pathname as well), so there is no way to access HomePage:

<Router>
  <Route path="/" component={HomePage} />
  <Route path="*" component={NotFoundPage} />
</Router>

If I reverse the order in which my routes are declared, then I get what I need. The following setup displays HomePage for pathname / and NotFoundPage for everything else:

<Router>
  <Route path="*" component={NotFoundPage} />
  <Route path="/" component={HomePage} />
</Router>

It feels weird having to declare 404 as the first item of my router, above my index page. Am I doing something wrong, or is this the intended behaviour?

I'm using svelte 3.2.0 and svero 0.2.4, Firefox 66 OSX.

Does not work with Webpack

Hello!
I'm trying to use svero with svelte webpack and it does not work

Steps:

  • npx degit sveltejs/template-webpack svelte-app
  • cd svelte-app
  • modify webpack.config.js to handle 404 by adding
devServer: {
    historyApiFallback: true
}
  • npm i
  • npm install --save svero
  • create folder pages in src
  • create file pages/Index.svelte (and add simple html like <h2>Hey</h2>)
  • create file pages/About.svelte (and add simple html like <h2>About</h2>)
  • in App.svelte
<script>
	import { Router, Route } from 'svero';

	import Index from './pages/Index.svelte';
	import About from './pages/About.svelte';
</script>

<h1>Hello Svelte!</h1>

<Router>
	<Route path="/" component={Index} />
	<Route path="/about" component={About} />
	<Route path="/about/:who/123/:where" component={About} />
</Router>

If you point to http://localhost:8080/about
it renders both Index and About

Passing parameter to Link

Hello guys,

I have a route:

<Route path="/comment/:postId" component={Comment} />

inside my PostList.svelte component. I have a Link defined in this way:

<Link href="/comment/???"> { item.comments_count } comments </Link>

My question is, how do I pass the id of the post inside Link's href prop? I have tried many solutions but none of these seems work 😭

Thanks to all in advance 😀

All page components are displayed (question)

// App.svelte
<script>
 // v1.0.0
  import { Router, Route } from "svero";

  import CreateTrademark from "./pages/trademark/CreateTrademark.svelte";
  import UpdateTrademark from "./pages/trademark/UpdateTrademark.svelte";
  import CreateEmbroidery from "./pages/embroidery/CreateEmbroidery.svelte";
</script>

<Router path="/directory">
  <Route path="/embroidery/create" component={CreateEmbroidery} />
  <Route path="/trademark/update" component={UpdateTrademark} />
  <Route path="/trademark/create" component={CreateTrademark} />
</Router>

If navigate to http:.. /directory/trademark/create, then not only CreateTrademark component is displayed, but also all previous components in <Router ..>(CreateEmbroidery,UpdateTrademark,CreateTrademark).

How can I specify to only the CreateTrademark component corresponding to the requested url is displayed?

trouble with spa routing

im having trouble with the spa routing

when i have two routes like this
`

  <Route path="#/en/about" component={About}/>

`
and i want to display #/en/about the page renders the first route #/en AND #/en/about

How to set "active" link?

When writing a menu using svero how can I get the active path to style the menu link with? I could use the router prop if the menu was rendered inside of the route but I would like to avoid that to keep things DRY.

<nav>
  <Link href="/today" class:active={ ??? }>Today</Link>
  <Link href="/planner" class:active={ ??? }>Planner</Link>
  <Link href="/food" class:active={ ??? }>Food</Link>
</nav>

<Router>
  <Route path="/" component={Home} />
  <Route path="/today" component={Today} />
  <Route path="/planner" component={Planner} />
  <Route path="/food" component={Food} />
</Router>

Reloads with default Svelte template

Using the default template (https://github.com/sveltejs/template) and a simple example of Svero I have a problem when the template on npm run dev reloads after a change in code.

The browser crashes because, let's say /page, "is not found".

Maybe this problem is not strictly related to Svero but have you an hint for us, newbies people?

Any plan to implement a layout system?

All is in the title!

Would like to display different layout based on the route we're on.

And already tried about doing it in my component, but the layout is being refresh when navigating from route to route.

Problems with redirect and condition

Hey Guys,

I have a route like this:

<script>
    imports(...views)
    import { logged } from "./store";

    let isLogged;

    const unsubscribe = logged.subscribe(value => isLogged = value);
</script>

<Router>
    <Route path="/" redirect="/login />
    <Route path="/login" component={Login} />
    <Route path="/orders" component={Orders} condition={isLogged} redirect="/login" />
    ...
</Router>

When I access localhost:5000 I expect to be redirected to login but nothing happens. Just a blank page. Am I doing something wrong? Also, this condition (isLogged) is a variable controlled by the Svelte's store. Its value gets updated after the user login but even after it succeded and the isLogged now shows true, I can't go to localhost:5000/orders. It keeps me sending to /login.

I can't spot what I'm doing wrong. Can you guys help me on this one? Thanks!

Path params with component prop

A component inside a Route seems to be includable via either

  1. component={About}
    or
  2. Using the slot as in <Route ... ><About/></Route>

In 1, it doesn't seem possible to pass "About" any props of my own.
In 2, it doesn't seem possible to access router.params.

Is it possible to allow both of these at once?

Official webpack-template broken with svero by default

By default, the webpack-template svelte projet excludes node_modules from the Svelte loader. This means svero breaks as it cannot be loaded. Removing the exclude rule makes everything work great.

	module: {
		rules: [
			{
				test: /\.svelte$/,
				exclude: /node_modules/,
				use: {
					loader: 'svelte-loader',
					options: {
						emitCss: true,
						hotReload: true
					}
				}
			},

trouble with spa nested routing

im having trouble with the spa routing

when i have two routes like this
<Route path="#" component={Home}/>
<Route path="#/about" component={About}/>

and i want to display #/about the page renders the first route # and #/about

it should only render #/about

How to handle redirects with parameters?

This router configuration

<Router>
  <Route path="/" redirect={`/date/${today}`} />
  <Route path="/date/:date" component={DayPage} />
</Router>

gives me Error: svero expects <Route redirect="/date/2019-05-05"> to send to an existing route. /date/2019-05-05 does not exists.. Is there a way to do this kind of redirect inside the router?

<Link> does not get locally scoped CSS classes

Setting a class to a component in Svelte normally adds a special class that is used to make it locally scoped (see https://svelte.dev/docs#style). This doesn't work with <Link>.

This Svelte code:

<style>
  .link { color: red }
</style>
<a href="/link" class="link">Red link</a>

produces this result:

<style>
.link.svelte-13u2rmm { color: red }
</style>
<a href="/link" class="link svelte-13u2rmm">Red link</a>

This code:

<script>
  import { Link } from 'svero';
</script>
<style>
  .link { color: red }
</style>
<Link href="/link" className="link">Red link</Link>

produces this result:

<style>
.link.svelte-13u2rmm { color: red }
</style>
<a href="/link" class="link">Red link</a>

so the link stays unstyled.

Issue in path="*" for site root

Starting a new project (using [email protected]), I set up my initial route as <Route path="*" component={MainPage} /> as I have done to great success in a previous project (running @0.5.0).

This rendered no route for the site root / (both Firefox and Chrome treat it as an empty string), but happily displayed the main page (currently just the text "Main Page") on every page, including other valid routes next to their contents.

Comments in open issues lead me to <Route exact path="" fallback component={MainPage} /> which does do what I want it to do, but is not as clear as path="*" and is not clearly documented in the readme.

As well as determining whether this is unintended, I'd appreciate any advice on whether exact should be applied to only the one route, all routes, only routes without a placeholder or even no routes at all as I'm not doing any nesting. The readme is informative but not super clear on this point.

when dev run

Route.svelte:24 Uncaught TypeError: required.forEach is not a function
at getProps (Route.svelte:24)
at Object.$$self.$$.update (Route.svelte:38)
at init (index.mjs:1342)
at new Route (Route.svelte:38)
at Array.create_default_slot_1 (About.svelte:7)
at create_slot (index.mjs:55)
at create_fragment (Router.svelte:165)
at init (index.mjs:1346)
at new Router_1 (Router.svelte:152)
at create_fragment$5 (App.svelte:13)

How to handle a "back" button?

I have a "Help" page with a "close" button that I would like to redirect to the previous page.

Is there a way to do that with svero?

I would like to do it either with a "Link" or a redirect call.

Thanks

Route not in parent component

I have this situation:

App.svelte:

<script>
  import { Router, Route } from "svero";

  import Navbar from "./Navbar.svelte";
  import Home from "./Home.svelte";
</script>

<div class="container">
  <Navbar />
  <Router>
    <Route path="*" component={Home} />
  </Router>
</div>

Navbar.svelte:

<script>
  import { Link } from "svero";
</script>

<nav class="text-center">
  <Link href="/">Home</Link>
  <hr />
</nav>

Home.svelte:

<h3 class="text-center">
  <b>This is Home</b>
</h3>

but it becomes:

<div class="container">
    <nav class="text-center">
        <a href="/" class="undefined">Home</a>
        <hr>
    </nav>
</div>
<h3 class="text-center home"><b>This is Home</b></h3>

I would expect h3 in div.container, like this:

<div class="container">
    <nav class="text-center">
        <a href="/" class="undefined">Home</a>
        <hr>
    </nav>
    <h3 class="text-center home"><b>This is Home</b></h3>
</div>

Am I wrong?

"svelte": "3.2.2",
"svero": "0.4.0"

Fix Travis-CI builds

It seems all builds are failing in Travis CI due to some issue with chromium and web drivers.

Until this is fixed we will not be acceping any PR (other than proposed fixes for this issue).

Cannot apply styles to link

Hi,

I am using the Link components like so: <Link href='/' className='someclass'>Some text</Link> and cannot figure out how to apply styles to it. I setup a <style></style> area and apply a style for the someclass class like so:

<style>
.someclass {
color: red;
}
</style>

The problem is that the styles aren't applied to the element. Normally Svelte generates local class names which hold the styles but none are generated for the link. Other regular elements like divs do get their local class names generated and styles properly applied. I also tried using Link href='/' class='someclass'>Some text</Link> with no luck either.

Thanks

Write tests

There are lots of things to improve in svero, and some rough edges yet to be smoothed in the brand-new Svelte 3.

Tests would prevent things from breaking without notice and help with contribution check.

[Question] I'm always getting a 404 status code

I don't understand if I'm doing something wrong or if it is an issue.

I wanted to try out svero, so I copied the example code, but if I try to access whatever endpoint that is not '/', I get a 404 status code, and nothing appears.

Here is my App.svelte file:

<script>
  import { Router, Route } from 'svero';

  import About from './pages/About.svelte';

</script>

<Router>
  <Route path="/about" component={About} />
</Router>

and here is my About.svelte file:

<script>
  export let router = {};
</script>

<h1>Hello World</h1>

I'm using svelte 3.15.0 and svero 1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.