Search code examples
angularcordovacordova-pluginscordova-ios

App-routing works in web build but not working in cordova build


I'm working on converting angular to cordova for mobile apps and for the routing, I have a menu which contains link to go to a different page. this link works in the web build but not in the cordova build. I've tried the following:

const routes: Routes = [
 {
   // routes set up
 }
]

export const UsersRouting = RouterModule.forRoot(routes, {onSameUrlNavigation: 'reload'});

            {url:'./home', text: 'Home', path: 'home'},
            {url:'/', text: 'Home2', path: 'home'},
            {url:'./', text: 'Home3', path: 'home'},
            {url:'./home', text: 'Home4'},
            {url:'/', text: 'Home5'},
            {url:'./', text: 'Home6'},
            {text: 'Home7', path: 'home'},
            {text: 'Home8', path: ''},
            {text: 'Home9', path: '/'},
            {text: 'Home10', component: HomeComponent}

I have the home path set up as

 {
path: 'home',
redirectTo: '',
pathMatch: 'full'
},

and another with path ''.

 {
path: '',
// more content
},

None of these work for cordova build, but they all do for the web build. What is the right way to go about this?


Solution

  • so I tried to print the url when the app was built in cordova and it gave a file url (file://link-to-the-app) so I used this instead:

    {text: 'Home', component: HomeComponent, outlet: 'center', url: window.location.href}
    

    and that worked perfectly