Git Product home page Git Product logo

Comments (9)

molefrog avatar molefrog commented on July 16, 2024 1

My question is—if I want the LinkComponent to always go to /sub/url, even when used on line 17, what would you suggest?

Just use ~/sub/url. The base path for default router is always /

from wouter.

molefrog avatar molefrog commented on July 16, 2024

Hi @jeerbl, could you share a piece of code? This is supposed to work.

from wouter.

jeerbl avatar jeerbl commented on July 16, 2024

Hi @molefrog, I made a CodeSandbox. I've actually seen something strange, looking deeper into the problem.

What I'm trying to do is to have the same component in two different contexts, go to the same URL, and Wouter actually does, but the href set on the <a> element is for some reason wrong and different than the path Wouter actually navigates to.

In that example, if you access /sub/url, you'll see the link prefixed with ~ go to the actually root URL /url. When you're in /url, the <Link> still goes to /url (which is what I want), but the URL displayed in href attribute of the <a> element is actually /sub/url.

First thing is, what should happen here in my opinion is to have the <a> href element to be the same as where Wouter navigates to.

Second thing is, should Wouter actually ignore the hrefs when navigating? Is this what's expected? It benefits my case but I'm not sure if that's what's expected here.

from wouter.

molefrog avatar molefrog commented on July 16, 2024

but the URL displayed in href attribute of the <a> element is actually /sub/url.

That's because you have a custom hrefs formatter, if you remove it you the href will be /url isn't that something you want?

from wouter.

molefrog avatar molefrog commented on July 16, 2024

The hrefs only affects the href attribute rendered and it is mostly needed for server-side rendering (e.g. when you use hash-based routing, the html rendered must be <a href="#/" /> and not <a href="/" />). It does not affect the actual client-side navigation.

from wouter.

jeerbl avatar jeerbl commented on July 16, 2024

I see, thank you. So just formatting and nothing else.

Closing this.

from wouter.

jeerbl avatar jeerbl commented on July 16, 2024

Actually reopening this for advice. I updated the CodeSandbox.

Here, in this new piece of code, the component LinkComponent is going to /url so, in the <Router base="/sub"> this link will be /sub/url and in the first <Router> line 17, it will go to /url.

My question is—if I want the LinkComponent to always go to /sub/url, even when used on line 17, what would you suggest?

I would want all links under the <Router> line 14 to always add /sub to the route.

from wouter.

molefrog avatar molefrog commented on July 16, 2024

Hi @jeerbl is this issue still relevant?

from wouter.

jeerbl avatar jeerbl commented on July 16, 2024

Hi @molefrog, actually it isn't! Closing this issue :)

from wouter.

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.