Giter Club home page Giter Club logo

Comments (3)

ItalyPaleAle avatar ItalyPaleAle commented on September 14, 2024 1

You can totally do /books* but that would lead to unexpected consequences, such as matching /booksmart too. Hence the recommendation to use both /books and /books/*, which comes from https://github.com/lukeed/regexparam (the library used to parse the strings)

Having to define the route twice is an annoyance, but it should be a relatively minor one...

If you absolutely needed to define the route only once, you should look into defining it using a custom regular expression, which however requires using maps rather than objects with this router. With your example:

const routes = new Map()
routes.set(/^\/books(\/(.*))?/i, Books)

This matches both /books (but not /booksmart) and /books/*

from svelte-spa-router.

ItalyPaleAle avatar ItalyPaleAle commented on September 14, 2024

See here for nesting: https://github.com/ItalyPaleAle/svelte-spa-router/blob/master/Advanced%20Usage.md#nested-routers

from svelte-spa-router.

frederikhors avatar frederikhors commented on September 14, 2024

@ItalyPaleAle I have read all about that.

The issue (exposed not very clearly, I admit) is this:

If I need to handle an URL like: mydomain.com/#/books (without final slash /) I need two routes like this:

routes = {
  '/books': Books,
  '/books/*': Books,
}

Is there a way to handle both #/books and #/books/* with just one route?

Is it clear now?

from svelte-spa-router.

Related Issues (20)

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.