本文整理汇总了TypeScript中history.createBrowserHistory函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createBrowserHistory函数的具体用法?TypeScript createBrowserHistory怎么用?TypeScript createBrowserHistory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createBrowserHistory函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: makeHistoryDriver
export function makeHistoryDriver(
options?: BrowserHistoryBuildOptions | History | MemoryHistory,
): HistoryDriver {
let history: any;
if (options && options.hasOwnProperty('createHref')) {
history = options;
} else {
history = createBrowserHistory(options);
}
return function historyDriver(sink$: Stream<HistoryInput | string>) {
return createHistory$(history, sink$);
};
}
示例2: createBrowserHistory
import { createBrowserHistory, createMemoryHistory, createHashHistory, createLocation, Location, History, MemoryHistory } from 'history';
import * as LocationUtils from 'history/LocationUtils';
import * as PathUtils from 'history/PathUtils';
import * as DOMUtils from 'history/DOMUtils';
import * as ExecutionEnvironment from 'history/ExecutionEnvironment';
let input = { value: "" };
{
let history: History<{some: 'state'}> = createBrowserHistory();
// Listen for changes to the current location. The
// listener is called once immediately.
let unlisten = history.listen(function (location) {
console.log(location.pathname);
});
// When you're finished, stop the listener.
unlisten();
// Push a new entry onto the history stack.
history.push('/home');
// Replace the current entry on the history stack.
history.replace('/profile');
// Push a new entry with state onto the history stack.
history.push({
pathname: '/about',
search: '?the=search',
state: { some: 'state' }
示例3: goto
static goto(routePath: string): History {
const history = createBrowserHistory();
history.push(`/${routePath}`);
return history;
}
示例4: createBrowserHistory
import { createBrowserHistory } from 'history'
const history = createBrowserHistory({
basename: '/intern',
})
export default history
示例5: combineReducers
import { createStore, combineReducers, applyMiddleware } from 'redux';
import { createBrowserHistory } from 'history';
import { syncHistory, routeReducer } from 'react-router-redux';
const reducer = combineReducers({ routing: routeReducer });
// Sync dispatched route actions to the history
const browserHistory = createBrowserHistory()
const reduxRouterMiddleware = syncHistory(browserHistory);
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware)(createStore);
const store = createStoreWithMiddleware(reducer);
// Required for replaying actions from devtools to
reduxRouterMiddleware.listenForReplays(store);
示例6: createBrowserHistory
import { createBrowserHistory } from 'history';
const history = createBrowserHistory();
export default history;
示例7: qhistory
import qhistory from 'qhistory';
import { createBrowserHistory } from 'history';
import * as qs from 'qs';
const history = qhistory(createBrowserHistory(), qs.stringify, qs.parse);
history.listen(location => {
const query: { foo?: string } = location.query;
if (query.foo) {
const foo: string = query.foo;
}
});
history.push({
pathname: '/',
query: {
foo: 'bar'
}
});
示例8: createBrowserHistory
import {createBrowserHistory} from "history";
export default createBrowserHistory();
示例9: createBrowserHistory
import './css/site.css';
import 'bootstrap';
import * as ko from 'knockout';
import { createBrowserHistory } from 'history';
import './webpack-component-loader';
import AppRootComponent from './components/app-root/app-root';
const baseUrl = document.getElementsByTagName('base')[0].getAttribute('href')!;
const basename = baseUrl.substring(0, baseUrl.length - 1); // History component needs no trailing slash
// Load and register the <app-root> component
ko.components.register('app-root', AppRootComponent);
// Tell Knockout to start up an instance of your application
ko.applyBindings({ history: createBrowserHistory({ basename }), basename });
// Basic hot reloading support. Automatically reloads and restarts the Knockout app each time
// you modify source files. This will not preserve any application state other than the URL.
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => ko.cleanNode(document.body));
}
示例10: require
import {createStore, applyMiddleware, compose} from "redux";
const History = require("history");
import {routerMiddleware as create_redux_router_middleware} from "react-router-redux";
const thunk = require("redux-thunk").default;
import CONFIG from "../../../shared/config";
import {all_reducers} from "./reducers";
import {AppState} from "./shape";
import {Action} from "./actions";
// tslint:disable-next-line
// https://github.com/ReactTraining/react-router/tree/dc2149ec0c63bfc95b71e40c81431e34cfbfeda9/packages/react-router-redux
export const history = History.createBrowserHistory();
const redux_router_middleware = create_redux_router_middleware(history);
const redux_router_store_enhancer = applyMiddleware(thunk, redux_router_middleware);
// tslint:disable-next-line
const glo = (window || global) as any;
// From: https://github.com/zalmoxisus/redux-devtools-extension#1-with-redux
let compose_enhancers = compose;
if (CONFIG.ENV_DEVELOPMENT && glo.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) {
compose_enhancers = glo.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
// Specify extensionâs options like name, actionsBlacklist, actionsCreators, serialize...
});
}
export const app_store = createStore<AppState>(
all_reducers,
compose_enhancers(redux_router_store_enhancer)
);