如何在cordova应用程序中配置node.js路由 [英] How to configure node.js routes in a cordova app

查看:250
本文介绍了如何在cordova应用程序中配置node.js路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个angular / cordova应用程序,其中从URL中删除并刷新后,页面不会被抓取,我一直收到错误像 -

I am working on an angular/cordova app, wherein after removing # from Url and refreshing, the pages are not getting fetched and I keep getting error like -

Cannot GET /home/index

如何配置node.js服务器为任何不匹配的路由返回index.html?

How can I configure node.js server to return index.html for any unmatched route?

推荐答案

首先,您不必担心可能的网址编辑,因为用户无法在使用应用程序时更改网址。但是,如果您在任何 anchor 标记上提供错误的网址,则 $ urlRouterProvider.otherwise('/')

Firstly, you shouldn't worry about the possible edit of URL, since a user cannot change the URLs while using the app. But yes, if you provide a wrong URL on any anchor tag, $urlRouterProvider.otherwise('/') will do that for you.

myApp.config(function($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/')

    $stateProvider.state('home', {
        url: '/',
        controller: 'homeCtrl',
    })

    $stateProvider.state('p1', {
        url: '/p1',
        templateUrl: "templates/p1.html",
        controller: "p1Ctrl"
    })
    ...
})

我可以知道你的index.html页面中的内容是什么?

And may I know what is the content in your index.html page?

这篇关于如何在cordova应用程序中配置node.js路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆