[SOLVED] Initial page and local storage


#1

I am working on an app that requires that once a user is already logged in, they dobnt have to to it all the time…

I create the general index.html as usual with CSS styles and panel, then…

<!DOCTYPE html>
<html lang="en">
<head>
...styles and the like...
</head>
<body>
  <div id="app">
    <div class="statusbar"></div>
    <div class="panel panel-left panel-cover">
      <div class="page">
        <div class="page-content">
           .......
        </div>
      </div>
    </div>

    <div class="view view-main ios-edges"></div>
    </div>
  </div>
....scripts....
</body>
</html>

In my app.js, I do this…

app.views.create('.view-main', {
  url: '/'
})

And then, in my routes.js, I have…

routes: [
  {
    path: '/',
   async: function (routeTo, routeFrom, resolve, reject) {
     if(loggedin)
      resolve({
          componentUrl: './pages/home.html'
      });
     else
      resolve({
          componentUrl: './pages/login.html'
      });
   }
  },
  ...
]

It keeps loading a white page… I am not sure if its because of the panel and if it is the panel, how do I deal with the fact the panel must be on the index page? I just want home.html found in pages folder as a component… the panel can stay in the DOM… I dont know what I am doing wrong… It just isn’t working… Kindly help…


View.router.navigate('/') doesn't work
#2

Do you have any errors in console? White page - means it doesn’t load anyhting. What is loggedin variable? Is it defined somewhere above?


#3

thanks @nolimits4web, but now it is funny how it behaves… It is redirecting me to page not found instead… Yet I create a main view in app.js at '/'homepage.html is a component found in defined directory (pages folder)… It now loads but PAGE NOT FOUND INSTEAD… I have no idea why it isn’t reading my '/' as the intial route… does panel code have an effect? I infact am using the official core kitchen sink to test and it keeps doing this… I cut the front page content on index.html and pasted it in <template></template> tags on homepage.html, create my main-view and customized the route…as below… I replaced <div class="view view-main view-init ios-edges" data-url="/"> with <div class="view view-main ios-edges"></div>

  {
   path: '/',
   async: function (routeTo, routeFrom, resolve, reject) {
         var loggedin = true;

     if(loggedin)
      resolve({
          componentUrl: './pages/homepage.html'
      });
     else
      resolve({
          componentUrl: './pages/login.html'
      });
   }
  },

I intend to pass localstorage in loggedin


#4

do you have live example?


#5

Oh yes @nolimits4web, I have this link here… This Code is shortened as possible to find the issue out immediately… It wont take much of your time… I couldn’t figure out a better way to do it in the jsfiddle…

Thanks in advance


#6

You need to disable pushState, otherwise you need to configure it correctly including setting correct pushStateRoot value


#7

@nolimits4web, Yep, that solved it… You are a genius! Couldn’t have thought of that…