Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Max Waterman
@davidmaxwaterman
hrm, that's worth knowing, thanks
Things have changed with the path: ['/page', '/page/index.html'] thing...but still not quite there.
Vladimir Kutepov
@frenzzy
Why not? If you are using a url generation - it uses the first path from the array, so in your case need to specify index.html first like this: path: ['/page/index.html', '/page']
Max Waterman
@davidmaxwaterman
hrm, ok...I'll try the other way around
Max Waterman
@davidmaxwaterman
What sort of interaction is there between the baseUrl and the path? Do you think I need both?
Vladimir Kutepov
@frenzzy
if you are using url generation, yes you need both
Max Waterman
@davidmaxwaterman
hrm, perhaps I don't understand this term 'url generation'....would you explain that term for me?
If it is as simple as my code generating the paths as strings and then adding the strings, then yes, I'm doing that.
ah, spotted a mistake...
Max Waterman
@davidmaxwaterman
ah, no
hrm...looks useful though
Vladimir Kutepov
@frenzzy
yep, to not add base url manually everywhere :)
Max Waterman
@davidmaxwaterman
yeah, that sounds familiar :/
however, it doesn't look like the URLs are wrong...well, let me see
Max Waterman
@davidmaxwaterman
hrm, I get my index.html page ok, but the other pages, with path of /root/view, don't seem to resolve.
I think the issue is that the baseUrl doesn't include the index.html - well, only for the first page
Vladimir Kutepov
@frenzzy
your website urls looks like this, right?
  • /sub-folder/index.html - main page
  • /sub-folder/root - sub page
  • /sub-folder/root/view - sub page
Max Waterman
@davidmaxwaterman
not quite...actually everything is under /sub-folder....
it's just that the index.html has to be explicit - so that's only for the first page, it seems
Vladimir Kutepov
@frenzzy
could you please show how urls looks like?
Max Waterman
@davidmaxwaterman
perhaps it is actually what you said
kind of
atm, I have baseUrl as '/subdir', and the paths as '/index.html' and '/view1'
but when it comes to this.router.resolve() with /subdir/index.html it goes to the catch()
Vladimir Kutepov
@frenzzy
ok, so
const routes = [
  { name: 'home', path: '/index.html', action: () => 'Home' },
  { name: 'view1', path: '/view1', action: () => 'View1' },
]
const router = new UniversalRouter(routes, { baseUrl: '/subdir' })

router.resolve({ pathname: '/subdir/index.html' }).then(result => console.log(result)) // => Home
router.resolve({ pathname: '/subdir/view1' }).then(result => console.log(result)) // => View1

const url = generateUrls(router)
url('home') // => /subdir/index.html
url('view1') // => /subdir/view1
Max Waterman
@davidmaxwaterman
right...that's what I have
I thought it wasn't working, but perhaps it is a debugger thing stopping on the wrong line or something
I'm using typescript, so maybe it's a source map problem confusing me
yes, it definitely working :D
I thought it had gone to my catch(), but it hadn't really...
So, that seems to be what I needed.
Vladimir Kutepov
@frenzzy
You can play with it here: https://jsfiddle.net/frenzzy/b0w9mjck/311/
Max Waterman
@davidmaxwaterman
There are some other things I need to change, but I think I need to apply the same there.
Thanks for that. It shows me how to use the url generator...I'll see if I can use that in my app - it's deep inside Redux somewhere, and I always get lost in there.
NB, I didn't write this, so it's a bit of a learning curve for me.
but you've been amazing - thanks very much!
Vladimir Kutepov
@frenzzy
You are welcome!
Rahul patel
@imrahulpatel
image.png
image.png
any please help me in this I am using react-stater-kit from last 2 year now I am updating it and I causing this issue
@imrahulpatel there are migration instructions in change log, JFYI: https://github.com/kriasoft/universal-router/releases/tag/v5.0.0
Vince Bello
@vincentbello
When following a client side route that resolves asynchronously, is there any way to hook into the UI (display some kind of spinner) to indicate that the data for the route is loading?
Vladimir Kutepov
@frenzzy
@vincentbello yes, show loader before router.resolve() and hide after route is resolved and rendered, for example:
async function navigate(pathname) {
  console.log('show loader')
  const result = await router.resolve(pathname)
  document.body.innerHTML = result
  console.log('hide loader')
}
Vince Bello
@vincentbello
ty @frenzzy !
Liz Mitchell
@asyncLiz

Hey all! I'm having a weird problem, I've got some middleware and it throws TypeError: Cannot read property 'route' of undefined instead of Error: Route not found for unknown routes:

    const router = new UniversalRouter({
      path: '/',
      async action({ next }) {
        console.log('middleware: start');
        const child = await next();
        console.log('middleware: end');
        return child;
      },
      children: [
        {
          path: '/hello',
          action() {
            console.log('route: return a result');
            return 'Hello, world!';
          }
        }
      ]
    });


    router.resolve('/hello/404');

I can't find an existing issue for this, is it a known problem?
https://jsbin.com/buzeloligu/2/edit?html,output

Vladimir Kutepov
@frenzzy
It contains the fix for the issue above