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

How to handle routing (add more pages) #9

Open
rizkysyazuli opened this issue Nov 8, 2018 · 2 comments
Open

How to handle routing (add more pages) #9

rizkysyazuli opened this issue Nov 8, 2018 · 2 comments

Comments

@rizkysyazuli
Copy link

I'm still touching the surface about this whole micro frontend and Tailor thing. But i'm curious on how to handle additional routes / pages with this approach?

  • Do we add react-router, for example, in the fragment that handles navigation? Does the other fragments even aware of the URL change? And what if we use a different framework on one of the fragments?
  • Or do we create some sort of universal router via the Tailor server?
  • Or something else? Like Zalando's own Skipper?

FYI, I'm just trying to start a discussion. Does not necessarily need a solution.

@armand1m
Copy link
Contributor

IMO, you should handle routing in Tailor.

You can have your component fragment servers running, and you can create a template for each route of yours and expose them through Tailor.

This gives you flexibility to change fragments on the fly without having to redeploy or change code.

In order to do that, just change the current ./tailor.js with these changes:

'use strict'

const http = require('http')
const Tailor = require('node-tailor')
const tailor = new Tailor({
  templatesPath: __dirname + '/templates'
})

http
  .createServer((req, res) => {
    if (req.url === '/favicon.ico') {
      res.writeHead(200, { 'Content-Type': 'image/x-icon' })
      return res.end('')
    }

    req.headers['x-request-uri'] = req.url
-   req.url = '/index'
+   if (req.url === '/') {
+     req.url = '/index'
+   }

    tailor.requestHandler(req, res)
  })
  .listen(8080, function() {
    console.log('Tailor server listening on port 8080')
  })

(someone please submit a pull request)

Now you can have different templates in the templates folder, one for each route.

When the route is /login, it will render the login.html template, for example.

@armand1m
Copy link
Contributor

armand1m commented Dec 3, 2018

Well, it happened that I just found some edge cases too.

For example, let's say I have an application with a Dashboard.

There is a fragment-dashboard and a dashboard.html template for Tailor to render it when I access /dashboard

In this dashboard, there is a menu list of sections in the dashboard you can access.

If I don't care about SSR or URL Sharing, it is just fine to use smth like react-tabs and change content dynamically.

But if I do, I need to include react-router or smth like this to handle different routes inside that specific fragment, so if a user access /dashboard/settings he gets at least redirected to the dashboard settings instead of only rendering the dashboard itself.

I can also decouple my fragment-dashboard into others such as fragment-dashboard-settings and create specific templates for each and tell Taylor to render dashboard-settings.html template whenever a user accesses /dashboard/settings for example.

In this way, I might not need react-router at all.

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