Skip to content
This repository has been archived by the owner on May 6, 2021. It is now read-only.

Unable to resolve routes with special characters #1104

Open
Artur- opened this issue Jan 30, 2020 · 1 comment
Open

Unable to resolve routes with special characters #1104

Artur- opened this issue Jan 30, 2020 · 1 comment
Labels
fusion CCDM related documentations Impact: Low Severity: Minor

Comments

@Artur-
Copy link
Member

Artur- commented Jan 30, 2020

I would assume this should succeed

    it("should resolve routes with special characters", async () => {
      const resolver = new Resolver([
        { path: "/ab", action: () => "a" },
        { path: "/a b", action: () => "b" },
        { path: "/a b (c)", action: () => "c" }
      ]);
      expect((await resolver.resolve("/ab")).result).to.be.equal("a");
      expect((await resolver.resolve("/a b")).result).to.be.equal("b");
      expect((await resolver.resolve("/a b (c)")).result).to.be.equal("c");
    });

but it fails with

Error: [Vaadin.Router] Page not found (/a b (c))
@vlukashov
Copy link
Contributor

vlukashov commented Feb 3, 2020

This is expected behavior in Vaadin Router since it uses path-to-regexp for the route path syntax, and that treats (, ), and a few other characters specially. If you need to include a ( literally, it needs to be escaped with a back slash: '\\(' (which itself has to be escaped in JS literal strings).

Here is the relevant group of unit tests: https://github.com/vaadin/vaadin-router/blob/master/test/resolver/matchPath.spec.js#L289

The real issue here is that neither Vaadin Router's docs, nor Flow docs explain the syntax.

@haijian-vaadin haijian-vaadin transferred this issue from vaadin/router Feb 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fusion CCDM related documentations Impact: Low Severity: Minor
Projects
None yet
Development

No branches or pull requests

3 participants