GithubHelp home page GithubHelp logo

Optional path segments about router HOT 4 CLOSED

mrkamel avatar mrkamel commented on May 27, 2024
Optional path segments

from router.

Comments (4)

posva avatar posva commented on May 27, 2024

See https://router.vuejs.org/guide/migration/#Removal-of-unnamed-parameters

In particular, what you want is this: https://paths.esm.dev/?p=AAMsIPQgYAwL9gdgGALADgWWMzAFpBLHCWgc4PKyMmA2gLgCbw4OigVg_AC5eGykoA1SD10A1AAAHATokaYUwAAQ&t=/companies/2/page/thing#

from router.

mrkamel avatar mrkamel commented on May 27, 2024

@posva thanks a lot 👍 The neccessary escaping of the closing brace is very weird, though, IMHO

from router.

mrkamel avatar mrkamel commented on May 27, 2024

Additionally, this doesn't fully help with generating a url as the (?:page/([^/]+?\))? is only a constraint when parsing a path, but has no effect when generating one

const matcher = createRouterMatcher(
  [{ name: "someRoute", path: "/prefix/:slug/:page(?:page/(\\d+\\))?" }],
  {},
);

matcher.resolve(
  { name: "someRoute", params: { slug: "test-123", page: 4 } },
  { params: {} },
)

// => /prefix/test-123/4

reproduction https://codesandbox.io/p/devbox/qpktzz?file=%2Findex.mjs%3A11%2C1-15%2C1

from router.

posva avatar posva commented on May 27, 2024

Escaping always reads weird.
Yes, you will have to provide the whole param: page/54. In your specific case though, the / will be encoded since it's a param so you will need to build the fullpath yourself: router.push(/prefix/${slug}/page/${page}). There are plans to improve the handling of the / encoding in params in the future though

from 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.