Class: Location

Location(location) → {Object}

new Location(location) → {Object}

创建location对象,类似window.location
Parameters:
Name Type Description
location String | Object 字符串为href;对象为{hash, host, hostname, href, origin, pathname, protocol, search},参考window.location
Source:
Returns:
- 返回对象{hash, host, hostname, href, origin, pathname, protocol, search, params, path}
Type
Object
Example
import router from 'digi-router'
let loc = new router.Location('http://localhost:8080/pathname?t=1&array=1&array=2#hash')
console.log(loc)
// => {
//      hash: '#hash',
//      host:'localhost:8080',
//      hostname:'localhost:8080',
//      href:'http://localhost:8080/pathname?t=1&array=1&array=2#hash',
//      origin: 'http://localhost:8080',
//      pathname: '/pathname',
//      protocol: 'http:',
//      search: '?t=1&array=1&array=2',
//      params: { t:'1', array: ['1', '2'] },
//      path: '/pathname?t=1&array=1&array=2#hash'
//    }

loc = new router.Location({ pathname: '/a', search: '?t=1' })
console.log(loc)
// => {
//      hash: '',
//      host:'localhost:8080',
//      hostname:'localhost:8080',
//      href:'http://localhost:8080/a?t=1',
//      origin: 'http://localhost:8080',
//      pathname: '/a',
//      protocol: 'http:',
//      search: '?t=1',
//      params: { t:'1' },
//      path: '/a?t=1'
//    }