Skip to content

Notfound pattern not working when '/' is also in use.  #16

@Cmdv

Description

@Cmdv

This issue turned up here

I spoke to @TylorS and we thought giving the use of /$ would help, I wrote tests but was unable to implement the required use as I can only get one test or the other to pass never both.

it('should match a root base path when using /$', () => {
    const {path, value} = switchPath('/abc', {
      '/$': 123,
      '/home': 456,
      '/bar': 789,
      '*': 'Route not defined'
    });
    expect(path).to.be.equal('/abc');
    expect(value).to.be.equal('Route not defined');
  });

  it('should still match a notFound pattern when using /$', () => {
    const {path, value} = switchPath('/', {
      '/$': 123,
      '/home': 456,
      '/bar': 789,
      '*': 'Route not defined'
    });
    expect(path).to.be.equal('/');
    expect(value).to.be.equal(123);
  });

and here is how far I got :

traverseRoutes(routes, function matchPattern(pattern) {
    if (pattern === `/$`) {
      matchedPath = pattern // matchedPath = `/` 
// it needs to be one or the other dependent on visited route falls in * or `/`

      matchedValue = routes[pattern]
    } else if (sourcePath.search(pattern) === 0 && betterMatch(pattern, matchedPath)) {
      matchedPath = pattern
      matchedValue = routes[pattern]
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions