Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Url ends with and without / is difference #7

Open
namleasia opened this issue Oct 19, 2021 · 1 comment
Open

Url ends with and without / is difference #7

namleasia opened this issue Oct 19, 2021 · 1 comment

Comments

@namleasia
Copy link

Currently, access these urls are difference:

/posts
/posts/

How to make these urls the same?

Currently, I have to define two paths for the same view:

const routes = [
        { path: "/posts", view: Posts },
        { path: "/posts/", view: Posts },
    ];
@Pant
Copy link

Pant commented Jan 17, 2022

try changing this:
const pathToRegex = path => new RegExp("^" + path.replace(/\//g, "\\/").replace(/:\w+/g, "(.+)") + "$");
to this:`const pathToRegex = path => new RegExp("^" + path.replace(///g, "\/").replace(/:\w+/?/g, "(.+)") + "$");

            result: location.pathname.match(pathToRegex(route.path))

to this:

            result: location.pathname.replace(/\/$/g, "").match(pathToRegex(route.path))

Note: Tested and works for me

felix-d1strict added a commit to felix-d1strict/single-page-app-vanilla-js that referenced this issue Jul 17, 2022
Following @Pant 's suggestion in dcode-youtube#7 (comment), I have made this change.

I have now tried it for a few days, and it seems to work well.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants