Switch to desktop version  
Custom page not working when using T2M (React, TypeScrypt) - Printable Version

+- Ewon Technical Forum (https://techforum.ewon.biz)
+-- Forum: Development (https://techforum.ewon.biz/forum-50.html)
+--- Forum: Custom Web Pages/viewON/Talk2M Visualization (https://techforum.ewon.biz/forum-55.html)
+--- Thread: Custom page not working when using T2M (React, TypeScrypt) (/thread-1025.html)



Custom page not working when using T2M (React, TypeScrypt) - ktmachinex - 25-09-2019

Hi,

I've created a custom web page using React framework and TypeScrypt. I then put it on the ftp of the ewon flexy 205 and configure the device to open by default on the custom page. Locally, when entering the ip address of the ewon, I can see my custom page and it works perfectly.

The problem occurred when I'm trying to access to my custom page while using T2M. It seens, the page has a problem reading the manifest.json file that I provided along the index.html page. See the attachment for more info.

Any idea why my page does not work when using T2M?

Thanks in advance,
ktmachinex


RE: Custom page not working when using T2M (React, TypeScrypt) - simon - 02-10-2019

Hi,

When you develop pages that must be seen through M2Web, you have to be careful to the links you use.
Indeed, M2Web parses your pages to replace the coded links by https://M2web.talk2m.com/account/ewon/restOfUrl.

If you want we have a closer look at your case, the best is to contact your local support representative.

Simon


RE: Custom page not working when using T2M (React, TypeScrypt) - ktmachinex - 02-10-2019

(02-10-2019, 01:21 PM)simon Wrote: Hi,

When you develop pages that must be seen through M2Web, you have to be careful to the links you use.
Indeed, M2Web parses your pages to replace the coded links by https://M2web.talk2m.com/account/ewon/restOfUrl.

If you want we have a closer look at your case, the best is to contact your local support representative.

Simon

Hi Simon,

Thanks for the reply. Is there any documentation about what I should be careful about when creating custom pages to have it work on M2Web?

I think my problem might have to do with using the react framework, how I create my routes within my custom page and/or how I manage my history (by hash).

I'll try to contact my local support representative.

Thanks again for all the help provided,
ktmachinex


RE: Custom page not working when using T2M (React, TypeScrypt) - simon - 03-10-2019

Hi,

Regarding your question "Thanks for the reply. Is there any documentation about what I should be careful about when creating custom pages to have it work on M2Web?", no there is no doc for that unfortunately.
If you develop it from scratch, I think that as long as you use relative links, everything should work fine in M2Web.

Usually what makes troubles is when absolute links are computed from the javascript...

Simon


RE: Custom page not working when using T2M (React, TypeScrypt) - ktmachinex - 03-10-2019

Hi,

All seems to point towards the navigation link href attribute.

Code:
// Is equal to this when view locally
<a class="nav-link" href="/settings/ewon">

// When view with Talk2M, it is changed for that
<a class="nav-link" href="#/machinex/RDHT Flexy Test/RDHT Flexy Test">

Now I'm trying to figure the proper fix to this.

Thanks for your time.

Any help is always welcome,
ktmachinex


RE: Custom page not working when using T2M (React, TypeScrypt) - simon - 08-10-2019

Hi,

You should perhaps use a relative link like "settings/ewon" or "../../settings/ewon" ?

Simon


RE: Custom page not working when using T2M (React, TypeScrypt) - ktmachinex - 31-10-2019

I finally found the problem / issue.

  • When accessing my custom web page locally, the address "index.html" has the location " / " and the route match " / ".
  • When accessing my custom web page through Talk2M, the address "index.html" has the location " / " and the route match " /[Talk2M account name]/[ewon device name]/ ".
This was messing up my routes and it could not render the proper component according to the link I clicked since the location would not match the route match.

Is this behaviour expected when using Talk2M (I'm no web developer expert by no mean)?

To fix the issue, I added a wildcard ('*') to every route like this:
Code:
<Switch>
            <Route path='*/home' component={Home}/>
            <Route path='*/users' component={Users}/>
            <Route path='*/about' component={About}/>
            <Route>             
                <NoMatch/>
            </Route>
          </Switch>




Here's the code I used to found the behaviour (the file was named App.js):
Code:
import React, { Component } from "react";
import { Switch, Route, Link, Redirect, HashRouter as Router, useLocation, useRouteMatch } from "react-router-dom";

function Home() {
  return (
    <div>
      <h2>Home</h2>
      {getRoutingInfo(useLocation(), useRouteMatch())}
    </div>
  );
}

function About() {
  return (
    <div>
      <h2>About</h2>
      {getRoutingInfo(useLocation(), useRouteMatch())}
    </div>
  );
}

function Users() {
  return (
    <div>
      <h2>Users</h2>
      {getRoutingInfo(useLocation(), useRouteMatch())}
    </div>
  );
}

function NoMatch(){
  let match = '/talk2mAccountName/DeviceName/';
  let location = useLocation();
  let routeMatch = useRouteMatch();

  if(location.pathname === '/' && routeMatch.path === match){
    return <Redirect to='/home' />
  }

  return (
    <div>
      <h2>No match for:</h2>
      {getRoutingInfo(location, routeMatch)}
    </div>
    );
}

function getRoutingInfo(location, match){
  return (
    <div>
      <h3>
        <ul>
          <li>Location: <code>{getLocationPath(location)}</code></li>
          <li>Router Match: <code>{getRouterMatch(match)}</code></li>
        </ul>
      </h3>
    </div>
  );
}

function getLocationPath(location){
  return location.pathname;
}

function getRouterMatch(match){
  return "[" + match.path + "] url: [" + match.url + "]";
}

class App extends Component {

renderNavBar(){
    return(
      <div className="container">
        <h1>Navigation bar</h1>
        <nav>
          <ul>
            <li>
              <Link to='/home'>Home</Link>
            </li>
            <li>
              <Link to='/users'>Users</Link>
            </li>
            <li>
              <Link to='/about'>About</Link>
            </li>
            <li>
              <Link to='/noMatch'>Will not match</Link>
            </li>
          </ul>
        </nav>
      </div>
    );
  }

  render(){
    return (
      <Router> {/* basename="usr/statsifier/machinex/RDHT/" | basename="/machinex/RDHT/" */}
        <div className="container">
          {this.renderNavBar()}
          <hr />

          {/*
            A <Switch> looks through all its children <Route>
            elements and renders the first one whose path
            matches the current URL. Use a <Switch> any time
            you have multiple routes, but you want only one
            of them to render at a time
          */}
          <Switch>
            <Route path='*/home' component={Home}/>
            <Route path='*/users' component={Users}/>
            <Route path='*/about' component={About}/>
            <Route>             
                <NoMatch/>
            </Route>
          </Switch>
        </div>
      </Router>
    );
  }
}

export default (App);

Thanks for your time.

It's always much appreciated.

Have a nice day,
ktmachinex


RE: Custom page not working when using T2M (React, TypeScrypt) - simon - 07-11-2019

Hi,

Yes, to me, this is an expected behavior. M2Web searches all links to replace them by m2web.talk2m.com/account/ewon/...

Very happy that it works now :-)

Simon